zoukankan      html  css  js  c++  java
  • struts2配置文件的解释

     1 <?xml version="1.0" encoding="GB2312"?> 
     2 <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> 
     3 //注解:<!-- struts 是struts2配置文件的根元素-->  
    <struts>  
      //注解:constant常量配置
    4  <constant name="struts.objectFactory" value="spring" /> //注解:指定struts2默认的objectFactorybean,该属性默认值是spring   5  <constant name="struts.devMode" value="false" /> //注解:是否使用开发模式,默认为false,测试阶段一般设为true   6  <constant name="struts.locale" value="zh_GB" /> //注解:<!-- 地区 -->en就是english;GB就是GreatBritain   7  <constant name="struts.i18n.encoding" value="GBK" /> //注解:指定web应用的默认编码集   8  <constant name="struts.action.extension" value="action" /> //注解:指定struts2处理请求的后缀名称   9  <constant name="struts.configuration.xml.reload" value="true" /> //注解:struts.xml文件系统改变后,系统是否重新加载该文件   10  <constant name="struts.serve.static" value="false" />  11 //注解:<constant name="struts.serve.static.browserCache " value="false" />   <!-- 当 struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false(生产环境下使用),开发阶段最好打开 -->   <constant  12 name="struts.custom.i18n.resources"value="ApplicationResources,errors" />  13 //注解:指定所需的国际化资源,以逗号分隔,   14  <constant name="struts.multipart.maxSize" value="2097152" /> //注解:设置上传文件允许的最大字节数   15  <constant name="struts.multipart.saveDir" value="/resources" /> //注解:设置上传文件所保存的临时文件夹   16  <constant name="struts.ui.theme" value="css_xhtml" />  17 //注解:设置主题    18 <constant name="struts.enable.SlashesInActionNames" value="true" />  31 //注解:设置Struts 2是否允许在Action名中使用斜线    32  <package name="login" namespace="/" extends="json-default"> //注解:name:必填,指定包的名字,该名字是该包被其他包引用的key 
      
    namespace:可选,定义该包的命名空间。   34 “/”表示根namespace,所有直接在应用程序上下文环境下的请求(Context)都在这个package中查找  35 “”表示默认namespace,当所有的namespace中都找不到的时候就在这个namespace中寻找  36          extends:可选,指定该包继承其他包。继承其他包,可以继承其他包中的Action定义、拦截器定义等   37  <action name="gotoIndex" class="IndexAction" method="gotoIndex">  38 //注解:name:请求的action的名称  39 Class:action处理类对应的具体的路径  40 Method:指定action中的方法名,如果没有指定method则默认执行action中的execute方法 Converter:指定action使用的类型转换器  41    <result name="success">     /admin/panel.jsp    </result>  42    <result name="failure">     /login.jsp    </result>   
      </action>    43   <action name="doFtp" class="IndexAction" method="doFtp">    <result name="success" type="redirect">      gotoIndex.action      </result>  44 //注解:name:对应action返回逻辑视图名称,默认为success,则页面跳转  45  Type:返回结果类型,默认为dispatcher(请求转发),可以设为redirect(重定向) 46    <result name="failure">     /login.jsp    </result>   
      </action>  47 <action name="login" class="LoginAction" method="login">    <result name="success">     /admin/main.jsp    </result>  48    <result name="failure">     /login.jsp    </result>   
      </action>  49  <action name="logout" class="LoginAction" method="logout">    <result name="success">  62     /login.jsp    </result>  63    <result name="failure">     /login.jsp    </result>  64  </action>          
    </package>

    请求转发和重定向的区别:

    转发和重定向设置:        
    <action name="deptAction" class="com.syaccp.erp.action.DeptAction">
                <result name="success">/WEB-INF/jsp/basic/dept_list.jsp</result>
                <result name="editView">/WEB-INF/jsp/basic/dept_edit.jsp</result>
    </action> 
        上例action中,success对应的视图是通过默认的转发(dispatch)跳转的。editView作为增删改的一部分,应该通过重定向来跳转页面,这样必须显式声明type=redirect,来达到重定向的效果。这时editView的内容改为action中一个方法更合适。如:
    <action name="deptAction" class="com.syaccp.erp.action.DeptAction">
                <result name="success">/WEB-INF/jsp/basic/dept_list.jsp</result>
                <result name="editView" type="redirect">deptAction!select.action</result>
    </action>
      这里在执行edit方法后返回editView字符串,将会再执行select方法,跟DeptEditServlet里response.sendRedirect("DeptListServlet")类似
    上例只是重定向同一个Action类中的其他方法,开发中可能还需要重定向到其他Action类中,这时就需要用到type属性的另一个值:redirectAction<action name="deptAction" class="com.syaccp.erp.action.DeptAction">
                <result name="success">/WEB-INF/jsp/basic/dept_list.jsp</result>
                <result name="editView" type="redirect">deptAction!select.action</result>
                <result name="index" type="redirectAction">indexAction.action</result>
    </action>
     上例中,如果deptAction中某个方法返回字符串为index,则将跳转到indexAction去,执行indexAction的execute方法。
    如果indexAction在其他包里面,则前面应加上包名,例:index/indexAction
  • 相关阅读:
    python,生产环境安装
    neo4j 图数据库
    RNN系列
    机器学习关于AUC的理解整理
    fensorflow 安装报错 DEPENDENCY ERROR
    dubbo Failed to check the status of the service com.user.service.UserService. No provider available for the service
    使用hbase遇到的问题
    MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk
    gradle 安装
    jenkins 安装遇到的坑
  • 原文地址:https://www.cnblogs.com/mryangbo/p/8268539.html
Copyright © 2011-2022 走看看