name 変数の値を送信する次のクラスがありますが、jsp には表示されません。hello world メッセージを表示するだけです
従業員.java
public class Employee {
private String name;
public Employee(){
this.name = "Daniel";
}
public String getName() {
return name;
}
public void setName(String name)
{
this.name = name;
}
Emp.java
public class Emp implements Controller {
private Employee empp;
protected final Log logger = LogFactory.getLog(getClass());
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("empp:"+this.empp.getName());
String myname = empp.getName();
logger.info("Returning hello view");
return new ModelAndView("emp.jsp","name",myname);
}
Emp.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<h2><c:out value="${name}"/></h2>
</body>
</html>
以下も使用
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("empp:"+this.empp.getName());
String myname = empp.getName();
logger.info("Returning hello view");
Map<String, Object> myModel = new HashMap<String, Object>();
myModel.put("name", this.empp.getName());
return new ModelAndView("emp.jsp","model",myModel);
}
Emp.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<h2><c:out value="${model.name}"/></h2>
</body>
</html>
使った
<h1><%= pageContext.findAttribute("model.name") %></h1>
しかし、それは Null を返します。