struts1配置文件中action的常用属性
来源:互联网 发布:怎么评价杨振宁知乎 编辑:程序博客网 时间:2024/05/29 02:26
首先列举action的属性代码如下:
<action path="URL"
type="ActionClass"
name="userForm"
scope="request"
attribute="key"
input="/register.jsp"
forward="/index.jsp"
include="/index.jsp"
unknown="true"
parameter="test"
className="mappingclass"
validate="true">
<forward name="" path=""></forward>
</action>
下面对其属性解析:
path:代表请求的Action的名称,无需指明后缀struts1自动处理
<form action="${pageContext.request.contextPath}/Register.do" method="post">....</form>
当其点击此提交时后缀名称为.do,(由于我们在会web.xml配置*.do的处理),所以经过mapping的地址映射,交给ActionServlet按照struts1的处理流程处理提交Action的请求。
type:代表请求的Action交给哪个Action处理,注意此类的名称一定是类的全名称(包括包名)。
name:代表的是请求参数封装的ActionForm的名称。
备注:此名称与<form-beans><form-bean name="名称Form" type="Form类的全名"></form-bean></form-beans>中"名称Form"一致,并通过此form-bean中的type来指定封装的ActionForm类。
scope:代表把formbean的参数封装到那个作用域中,默认的作用域为session。
备注:当我们没有指定formbean的作用域时,在type指定的Action类中还可以通过以下代码获取:
UserForm userForm = (UserForm) form;
/**
* 由于在Action的属性配置中的scope属性指定了userForm的作用域, 当采用的是默认值(session)时,
* 也可以直接从作用域中获取代码如下:UserForm userForm =
*(UserForm)request.getSession().getAttribute("userForm");
*/
/**备注:由于在开发中为了节省ActionForm占用的内存空间,一般采用scope=”request”配置,因此也可以采用一下的方式获取*/
UserForm userForm = (UserForm) request.getAttribute("userForm");
注意:若aciton的配置中没有配置attribute="key" 属性时,在Action中获取的关键字采用默认的值及name的名称,当配置了attribute="key"属性时,必须通过"key"获取。
attribute:指定formbean存储的key,不设默认为name属性的值。
举例:如果在action的配置中配置了attribute=”uform”,在Action中获取的方式应该为:
/** 通过方法参数中传递的ActionForm获取ActionForm中的对象并强制造型为UserForm */
UserForm userForm = (UserForm) form;
/**由于在action的配置中指明了attribute的属性及属性值,因此应该采用以下方式获取*/
UserForm userForm = (UserForm) request.getAttribute("uform");
input="/register.jsp" 指定formbean的数据是由哪个页面提供的。
说明:提供此属性的目的在于formbean校验失败时,程序方便跳回formbean的输入页面,通过struts1错误信息标签,显示校验失败信息。
forward="/index.jsp" 指定收到请求时,跳转到相应的jsp页面。
强调:如果配置了此属性,则action将不再被调用,即接受到此action时,直接调至到index.jsp页面。
include="/index.jsp" 指定收到请求时,进行页面包含。
unknown="true" 如果action把该属性设置为true,则它可以处理客户机发出的所有无效的.do请求,默认值为false。
举例:如果在配置文件中添加如下的action配置,<action path="/**" forward="/index.jsp" unknown="true"/>,当如果在地址栏中发出请求为:http://localhost:8080/20110105struts1_2/regi.do
如果在此配置文件中找不到regi.do的Action就会处理上面配置的action直接跳转到index.jsp页面 (备注:与此action中path名称无关,但必须配置一个path属性)。
parameter="test" 配置action参数,调用actioMapping.getParameter方法可以获得这里配置的参数。
className="mappingclass" <action>标签和所有的配置信息使用哪个对象封装,默认值为ActionMapping对象。
validate="true" 请求参数封装到formbean中后,是否让struts自动调用formbean的validate方法进行数据校验,默认true。
forward标签
在action配置中,还有一些其他的标签配置,<forward name="" path=""></forward>即在处理完此action之后可以在Action中的execute方法中通过此标签的name属性获取此action,并跳转到相应的path地址中。
举例:如果在action内部我们配置了forward标签的代码如下:
<forward name="message" path="/message.jsp"></forward>
那么可以再Action返回值中做如下处理:
/** 获取跳转的地址并返回ActionForward */
return mapping.findForward("message");
通过以上配置,在处理完此action后,struts1经过处理后就会跳转到/message.jsp视图层。
阅读全文
0 0
- struts1配置文件中action的常用属性
- struts1配置文件中action常用的属性
- struts1配置文件中action的常用属性
- struts1的配置文件属性
- struts1中几种常用的Action
- struts1中几种常用的Action
- Struts1 Action中各个属性 详解
- struts1.2中<action>parameter属性问题
- Struts1 Action 属性详解
- struts2配置文件中Action中的各属性的含义
- struts1.1 配置文件属性
- struts1.1 配置文件属性
- Struts1的struts-config.xml中action-mappings的parameter 属性详解
- 关于Struts1.2配置文件的Action访问路径相关问题
- struts1和struts2中Action的区别
- struts1.3中常用两种Action的子类 MappingDispatchAction和DispatchAction
- struts配置文件中action元素属性设置
- struts1中action参数
- 他们三人都答对的题目至少有多少?
- 初学python(一)
- Java线程基础-CountDownLatch-批量执行多线程完成,再由主线程发起
- java synchronized修饰方法和修饰方法块
- Xamarin.Forms 用户界面——控件——View
- struts1配置文件中action的常用属性
- hdu3460 Ancient Printer(字典树)
- (CCF 201403-4)无线网络 最短路变形:节点访问限制 + [SPFA]
- 18_集合框架
- STC15单片机控制舵机程序-智能报警系统
- First_Mark
- 十大数据挖掘算法
- javascript之(五)面下个对象
- 网络配置(有线、无线)