标签:ring ESS 基本数据 属性 数据类型 sys class rac rri
Strust2 get/set 自动获得/设置数据
1.自定义action ,添加属性
public class HelloStuts2Action implements Action{ private String name; public String getName() { return name; } public void setName(String name) { this.name = name; }
2.跳转新jsp页面,调用属性name
<body> ${name}HELLO WORD! </body>
ActionSupport类引入
public class ActionSupport implements Action, Validateable, ValidationAware, TextProvider, LocaleProvider, Serializable
1.新action继承Actionsupport
public class HelloStuts2Action2 extends ActionSupport{ /** * */ private static final long serialVersionUID = 1L; private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String execute() throws Exception { System.out.println("执行了 action默认方法"); // TODO Auto-generated method stub return Action.SUCCESS; } }
2.Action设置数据
第一种方式:属性驱动(FieldDriven)
A、基本数据类型属性
public class HelloStuts2Action2 extends ActionSupport{ private String name; }
B、JavaBean 类型属性
public class User { private String name; private String pwd; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } @Override public String toString() { return "User [name=" + name + ", pwd=" + pwd + "]"; } }
测试
1.搭建测试环境,新建login页面
login页面
<body> <form action="" method="post"> 用户名:<input name="name" type="text" /><p/> 密 码:<input name="pwd" type="text" /><p/> <input type="submit" value="登陆" /><p/> </form> </body>
success页面
<body> 用户名:${name} 用户名:${pwd} </body>
error页面
<body> 帐号或密码错误!登录失败 </body>
2.配置struts.xml
<action name="user_login" class="com.lin.action.UserAction"> <result name="success">succssful.jsp</result> <result name="error">error.jsp</result> </action>
3.action 逻辑存储
基本数据类型属性:
@Override
public String execute() throws Exception {
if (name.equals("lin") && pwd.equals("123")) {
return Action.SUCCESS;
}
return Action.ERROR;
}
JavaBean 类型属性
public String execute() throws Exception {
LoginSerivce serivce = new LoginSerivce();
boolean result = serivce.isLogin(new User(name, pwd));
if (result) {
return Action.SUCCESS;
}
return Action.ERROR;
}
第二种方式:模型驱动(ModelDriven) 只能接受一个bean对象
1.实现接口
public class UserAction extends ActionSupport implements ModelDriven<User>{
2.重新getmodel方法
User user = new User(); @Override public User getModel() { return user; }
标签:ring ESS 基本数据 属性 数据类型 sys class rac rri
原文地址:https://www.cnblogs.com/linbin7/p/11965213.html