POJO(Plain Old Java Objects)简单的Java对象,实际就是普通JavaBeans,是为避免和EJB混淆所创造的简称
Property-Driven示例
标签name名与Action和POJO中名称保持一致即可
①.JSP
- <s:form action="login.action" method="post" theme="simple">
- <input type="text" name="userName" />
- <br />
- <input type="text" name="password" />
- <br />
- <s:submit name="login" value="登陆" method="login"></s:submit>
- <s:submit name="add" value="新增" method="add"></s:submit>
- </s:form>
②Action
- public class LoginAction extends ActionSupport implements SessionAware,
- ServletRequestAware {
- private String userName;
- private String password;
- private String message;
- //省略get set方法
③POJO
- public class User {
- private String userName;
- private String password;
Model-Driven示例
在Action中定义整个POJO的对象并生成get set方法,在JSP调用时候,需要在属性名前加对象名
①JSP
- 用户名:<s:textfield name="user.userName" id="user.userName"></s:textfield><br />
- 密码:<s:password name="user.password" id="user.password"></s:password> <br />>
②Action
- public class RegisterAction {
- private User user;
③POJO
- public class User {
- private String userName;
- private String password;
时间: 2024-10-05 05:06:17