action与servlet API ModelDriven接口 异常
来源:互联网 发布:数据录入项目外包 编辑:程序博客网 时间:2024/05/17 01:08
1.通过ActionContext类访问
ActionContext context=ActionContext.getContext();context.put("name", "request:tom");context.getApplication().put("name", "application:tom");context.getSession().put("name", "session:tom");
${applicationScope.name}<br/>${sessionScope.name}<br/>${requestScope.name}<br/>
2.通过特定接口
ServletRequestAware
ServletResponseAware
ServletContextAware
3.通过ServletActionContext访问
ModelDriven接口
public class LoginAction extends ActionSupport implements ModelDriven<UserModel>{private static final long serialVersionUID = 1L;//创建UserModel实例 private UserModel user=new UserModel(); //getter方法,必须实现public UserModel getModel() {// TODO Auto-generated method stubreturn user;}//重载execute方法 public String execute() throws Exception { //得到ActionContext实例 ActionContext context=ActionContext.getContext(); //将(“user”,user)放入ActionContext中 context.put("user", user); return SUCCESS; }}
public class UserModel {//UserModel类的name、age、address、telephone属性private String name;private String age;private String address;private String telephone;//各个getter、setter方法public String getName() {return name;}public void setName(String name) {this.name = name;}public String getAge() {return age;}public void setAge(String age) {this.age = age;}public String getAddress() {return address;}public void setAddress(String address) {this.address = address;}public String getTelephone() {return telephone;}public void setTelephone(String telephone) {this.telephone = telephone;}}
<s:form action="user"><s:textfield label="Name" name="name"></s:textfield><s:textfield label="Age" name="age"></s:textfield><s:textfield label="Telephone" name="telephone"></s:textfield><s:textfield label="Address" name="address"></s:textfield><s:submit></s:submit></s:form>
<center><s:property value="#user.name"/><br/><s:property value="#user.age"/><br/><s:property value="#user.telephone"/><br/><s:property value="#user.address"/><br/></center>
异常
<struts> <package name="default" namespace="/" extends="struts-default"> <global-results> <result name="Exception">/Exception.jsp</result> <result name="SQLException">/SQLException.jsp</result> </global-results> <global-exception-mappings> <exception-mapping exception="java.sql.SQLException" result="SQLException"/> <exception-mapping exception="java.lang.Exception" result="Exception"/> </global-exception-mappings> <action name="user" class="com.action.UserAction"> <exception-mapping exception="com.action.SecurityException" result="login"/> <result name="login" >/loginException.jsp </result> <span style="white-space:pre"></span><result>/success.jsp</result> </action> </package> </struts>
0 0
- action与servlet API ModelDriven接口 异常
- Struts2 Action与Servlet API耦合
- Struts2 Action与Servlet API耦合
- DemanModle , ModelDriven与 Action属性接收参数
- Action访问Servlet API
- Action访问Servlet API
- Action实现ModelDriven接口后的运行流程
- Struts之Action(Action继承类、实现接口、访问servlet API方法)
- ModelDriven接口
- Action中访问Servlet API
- struts2 Action访问Servlet Api
- Struts2--------Action访问Servlet API
- Action访问Servlet API
- Action中访问Servlet API
- action之访问Servlet API
- Struts2 Action访问Servlet API
- 通过Action访问Servlet API
- Struts2-Action访问Servlet API
- ImageLoader 线程池 单例 使用模板
- 【NGUI】NGUI血条制作,当人物移出屏幕后不显示血条,优化代码
- c3p0的DriverManagerDataSource源代码看单例
- LeetCode Simplify Path
- hdu5275 (插值法)
- action与servlet API ModelDriven接口 异常
- 关于File的一点东西
- Java随机验证吗
- LeetCode Set Matrix Zeroes
- jquery操作select(取值,设置选中) 取得已选的值
- 单例模式 - 创建者模式
- 有关Google面试的资料集合
- android edittext + listview 实现搜索listview中的内容
- Majority Element II