我有一个名为Leave Controller的控制器,如下所示。
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class LeaveController {
@RequestMapping("/")
public ModelAndView loginPage()
{
return new ModelAndView("jsp/login.jsp", "command", new Employee());
}
@RequestMapping(value="verify" ,method=RequestMethod.POST)
public String verify(Employee eform,ModelMap model)
{
System.out.println(EmployeeAccessService.verify(eform));
model.addAttribute("uname",eform.getName());
model.addAttribute("pass",eform.getPassword());
return "jsp/home.jsp";
}
}
login.jsp页面的方法发送一个收到的员工pojo作为' eform'。我在转到home.jsp页面之前将两个属性添加到(ModelMap)模型。
这是我的home.jsp页面。
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>Home</title>
</head>
<body>
$(uname)<br>
$(pass)
</body>
</html>
问题是$(uname)和$(pass)显示为文本而不是变量。如何将它们显示为变量?
答案 0 :(得分:0)
不是$()
,而是${}
:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>Home</title>
</head>
<body>
${uname}<br>
${pass}
</body>
</html>