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

最新文章

  1. mui小总结
  2. Spring源码解析 - AntPathMatcher
  3. 每天checklist所用到的T-CODE
  4. cf592d
  5. ZOJ 3872 Beauty of Array
  6. c# 迭代器 与 集合 IEnumerable.GetEnumerator 方法
  7. 1TB到底能存放多少东西?
  8. JSP中的include有哪些?有什么差别?
  9. 从0.5开始学Java 零
  10. 关于安装了VMware tools后仍然不支持拖拽文件的问题
  11. java 获取文件内所有文件名
  12. [原创]K8飞刀Final
  13. Could not find default endpoint element that references contract &#39;wcfXXXXXXXXXXX&#39; in the ServiceMode
  14. 使用VS2015开发asp程序让IIS express 允许的父路径的方法
  15. 洛谷P2680运输计划
  16. 在VS中写js的同学注意了。。。。。。。。。。。。。。。。。。。
  17. Spring Cloud 架构 五大神兽的功能
  18. .NET读取服务器或本地文件
  19. (转载)深入super,看Python如何解决钻石继承难题
  20. swift3.0 原生网络请求

热门文章

  1. 微信小程序之目录结构
  2. STL的一些技巧函数使用
  3. python2 encode和decode函数说明
  4. 使用airmon-ng工具开启监听模式
  5. Python 中的 is 和 == 编码和解码
  6. [原创]20行ruby代码实现依赖注入框架
  7. Python基础学习六 操作MySQL
  8. 有一些sql 是必须要做笔记的!!
  9. smack 监听不同packet机制
  10. git配置和使用