文档详情

struts-config配置文件属性.doc

发布:2017-08-02约1.92千字共2页下载文档
文本预览下载声明
Struts-config.xml 配置文件《action-mappings》元素的详解 action-mappings 该元素用于将Action元素定义到ActionServlet类中,它含有0到多个action/元素,其格式如下: action-mappings action path=Action请求的相对路径,与页面html:form的Action属性值一致 type=该Action的对应类的全路径 name=该Action绑定的FormBean,与form-bean 的Name属性值一致 forward name=与Action类中mapping.findForward(mapname)返回的mapname值一致 path=页面跳转的相对路径/ /action /action-mappings 每个action子元素可包含一个或多个forward子元素。除了path、type和name属性外,action还具有如下属性: ? scope:指定ActionForm Bean的作用域(session和request),缺省为session。(可选); ? input:当Bean发生错误时返回的路径,在validate验证框架中错误显示的页面(可选); ? classname:指定一个调用这个Action类的ActionMapping类的全名。缺省用org.apache.struts.action.ActionMapping(可选); ? include:如果没有forward的时候,它起forward的作用(可选); ? validate:若为true,则会调用ActionForm的validate()方法或调用validate验证,否则不调用,缺省为true(可选)。 forward属性也是可选的。 action Eg1. 仅有JSP的action元素: action-mappings action path=/userAction type=com.amigo.struts.action.UserAction name=UserForm scope=request validate = false parameter=method forward name=error path=/user/error.jsp / forward name=success path=/user/success.jsp/ forward name=add path=/user/addUser.jsp/ forward name=update path=/user/updateUser.jsp/ forward name=list path=/user/userList.jsp/ /action /action-mappings Eg2. 有input属性的例子: action-mappings action path=/calcAction type=com.amigo.struts.action.CalcAction name=CalcForm scope=request validate=true input=/index.jsp forward name=success path=/success.jsp/ forward name=error path=/error.jsp/ /action /action-mappings 首先,ActionServlet接到请求后调用ForwardAction的execute()方法,execute()根据配置的parameter属性值来forward到那个URI。 action path=/menu parameter=/default.jsp type=org.apache.struts.actions.ForwardAction / 这样做的效果是:没有任何form被实例化,比较现实的情形可能是form在request更高级别的范围中定义;或者这个action被用作在应用程序编译好后充当系统参数,只需要更改这个配置文件而不需要重新编译系统。
显示全部
相似文档