服务器端一切正常都能正常显示
jsp页面中中el表达式无法显示出Struts2的基本属性注入的参数,只能显示Struts2的域模型注入的参数,求大神指点拿出的问题?
action如下
package action;
import entity.User;
public class HelloAction {
public HelloAction() {
System.out.println("实例化Action...");
}
// 定义基本类型属性,接收表单参数:姓名
private String realName;
public void setRealName(String realName) {
System.out.println("注入参数realName...");
this.realName = realName;
}
public String getRealName() {
return this.realName;
}
//定义实体对象属性,接收表单参数:用户名、密码
private User user;
public void setUser(User user) {
System.out.println("注入对象user...");
this.user = user;
}
public User getUser() {
return this.user;
}
/**
* 在业务方法中输出“Hello,Action.”
*/
public String sayHello() {
System.out.println("Hello,Action.");
// 输出基本类型数据
System.out.println("姓名:" + realName);
// 输出域模型方式注入的参数
System.out.println("用户名:" + user.getUserName());
System.out.println("密码:" + user.getPassword());
return "success";
}
}
表单页面
<form action="/Struts2/demo/hello.action" method="post">
<!--演示基本属性注入 -->
姓名:<input type="text" name="realName"/><br/><br/>
<!--演示域模型注入 -->
用户名:<input type="text" name="user.userName"/><br/><br/>
密码:<input type="text" name="user.password"/><br/><br/>
<input type="submit" value="提交"/>
</form>
输出页面
<body>
<h1>Hello,Struts2.</h1>
<h1>姓名:${realName }</h1>
<h1>用户名:${user.userName }</h1>
<h1>密码:${user.password }</h1>
</body>