转载自~ 在Struts2中,从Action中取得request,session的对象进行应用是开发中的必需步骤,那么如何从Action中取得这些对象呢?Struts2为我们提供了四种方式.分别为servlet 不相关的 非IoC 取得Request等对象的方式servlet 不相关的 IoC 取得Request等对象的方式servlet 相关的 非IoC 取得Request等对象的方式servlet 相关的 IoC 取得Request等对象的方式以下分别叙述.首先请看struts.xml文件文…
先看GetRequestParameterAction类代码:  Java代码 public class GetRequestParameterAction extends ActionSupport { private String bookName; private String bookPrice; public String getBookName() { return bookName; } public void setBookName(String bookName) { this…
先看GetRequestParameterAction类代码: public class GetRequestParameterAction extends ActionSupport { private String bookName;private String bookPrice; public String getBookName() {return bookName;} public void setBookName(String bookName) {this.bookName =…
此系列博文基于同一个项目已上传至github 传送门 JavaWeb_(Struts2框架)Struts创建Action的三种方式 传送门 JavaWeb_(Struts2框架)struts.xml核心配置.动态方法调用.结果集的处理 传送门 JavaWeb_(Struts2框架)Log4j的配置以及解决中文乱码 传送门 JavaWeb_(Struts2框架)参数传递之接收参数与传递参数 传送门 JavaWeb_(Struts2框架)Ognl小案例查询帖子 传送门 JavaWeb_(Struts…
在struts2的Action中,操作域对象一共有三种方式: 1.ActionContext(与servelt API无关联): //相当于request ActionContext.getContext().put("userName", user.getUserName()); //相当于session ActionContext.getContext().getSession().put("userName", user.getUserName()); //相…
上面两篇文章已经介绍了通过编码java代码的方式实现action方法校验,这里我们介绍第二种方式:xml配置文件 首先我们来看一个样例: ValidateAction.java: package com.itheima.action; import com.opensymphony.xwork2.ActionSupport; public class ValidateAction extends ActionSupport { private String username; private S…
struts2输入校验流程: 1.类型转换器对请求參数运行类型转换,并把转换后的值赋给aciton中的属性 2.假设在运行类型转换的过程中出现异常,系统会将异常信息保存到ActionContext, conversionError拦截器将异常信息加入到fieldErrors里,无论类型转换是否出现异常,都会进入第三步 3.系统通过反射技术先调用action的validateXXX方法 4.再调用aciton中的validate方法 5.经过上述的4步.假设系统中的fieldErrors存在错误信…
index.jsp: <body> <s:fielderror /> <form action="${pageContext.request.contextPath }/cn/person_add.do" method="post"> <table> <tr> <td>用户名:</td> <td><input name="userName" ty…
接触过webwork和Struts2的同行都应该知道, 提交表单的时候,只要Action中的属性有setter 方法,这些表单数据就可以正确赋值到Action中属性里:另外对于Spring配置文件中声明的bean,也可以在Action中声明setter 方法将其注入到Action实例中.那么现在要研究:这些是怎么工作的呢? (1)提交表单时的参数 在struts2-core-2.3.1.2.jar压缩包内的struts-default.xml配置文件中有这个配置:<interceptor nam…
尊重版权:http://hi.baidu.com/dillisbest/item/0bdc35c0b477b853ad00efac 在Struts2里,假设须要在Action中使用session.能够通过以下两种方式得到1.通过ActionContext class中的方法getSession得到2.Action实现org.apache.struts2.interceptor.SessionAware接口的方式来对session进行操作 以下先看一个採用第一种方式.在action中得到sessi…