模型驱动与属性驱动区别

POJO(Plain Old Java Objects)简单的Java对象,实际就是普通JavaBeans,是为避免和EJB混淆所创造的简称
 
Property-Driven示例
 
标签name名与Action和POJO名称保持一致即可
①.JSP
  1. <s:form action="login.action" method="post" theme="simple">
  2. <input type="text" name="userName" />
  3. <br />
  4. <input type="text" name="password" />
  5. <br />
  6. <s:submit name="login" value="登陆" method="login"></s:submit>
  7. <s:submit name="add" value="新增" method="add"></s:submit>
  8. </s:form>
②Action
  1. public class LoginAction extends ActionSupport implements SessionAware,
  2.         ServletRequestAware {
  3.     private String userName;
  4.     private String password;
  5.     private String message;   
  6.     //省略get set方法
③POJO
  1. public class User {
  2.     private String userName;
  3.     private String password;

Model-Driven示例
 
在Action定义整个POJO的对象并生成get set方法,在JSP调用时候,需要在属性名前加对象名
 
①JSP
  1. 用户名:<s:textfield name="user.userName" id="user.userName"></s:textfield><br />
  2. 密码:<s:password name="user.password" id="user.password"></s:password>    <br />>          
②Action
  1. public class RegisterAction {
  2.     private User user;
③POJO
  1. public class User {
  2. private String userName;
  3. private String password;
posted @ 2016-10-24 21:43  IT小甲鱼  阅读(918)  评论(0编辑  收藏  举报