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

struts2配置文件的解释的更多相关文章

  1. Struts2 配置文件小结

    每次写的博文都被管理员都被移出首页,好气!还希望有哪位大神可以指点迷津-- struts2 配置文件的 result 节点 result 节点是 action 节点的子节点,他代表着 action 方 ...

  2. Struts2配置文件详解

    解决在断网环境下,配置文件无提示的问题我们可以看到Struts.xml在断网的情况下,前面有一个叹号,这时,我们按alt+/ 没有提示,这是因为” http://struts.apache.org/d ...

  3. Struts2 配置文件result的name属性和type属性

    Struts2 配置文件result的name属性和type属性:Name属性SUCCESS:Action正确的执行完成,返回相应的视图,success是 name属性的默认值: NONE:表示Act ...

  4. Struts2配置文件模板

    <?xml version = "1.0" encoding = "UTF-8"?><!--下面是Struts2配置文件的DTD信息 --&g ...

  5. Struts2配置文件

    Struts2配置文件 简介: 与Struts2相关的配置文件有好几个,常用的有 struts.properties , web.xml, struts.xml等.web.xml中配置Struts2的 ...

  6. struts2配置文件中action的name属性

    struts2配置文件中action的name属性的第一个字符不要加斜杠 <action name="see" class="baoxiuManage_seeAct ...

  7. Struts2配置文件讲解

    解决在断网环境下,配置文件无提示的问题我们可以看到Struts.xml在断网的情况下,前面有一个叹号,这时,我们按alt+/ 没有提示,这是因为” http://struts.apache.org/d ...

  8. my.cnf 配置文件参数解释

    my.cnf 配置文件参数解释: #*** client options 相关选项 ***# #以下选项会被MySQL客户端应用读取.注意只有MySQL附带的客户端应用程序保证可以读取这段内容.如果你 ...

  9. 分布式文件存储FastDFS(七)FastDFS配置文件具体解释

    配置FastDFS时.改动配置文件是非常重要的一个步骤,理解配置文件里每一项的意义更加重要,所以我參考了大神的帖子,整理了配置文件的解释.原帖例如以下:http://bbs.chinaunix.net ...

随机推荐

  1. Java中的intern变量的讲解

    一般我们变成很少使用到 intern这个方法,今天我就来解释一下这个方法是干什么的,做什么用的 首先请大家看一个例子: public static void main(String[] args) t ...

  2. log4net 使用总结- (3)在ASP.NET MVC 中使用

    把输出到sqlserver数据库中. 输出到数据库中和文件中类似,具体配步骤如下 第一步.创建数据库 CREATE TABLE [dbo].[Log] ( [Id] [int] IDENTITY (1 ...

  3. log4net 使用总结- (1)在ASP.NET MVC 中使用

    1. 去官网下载log4net.dll,增加引用到站点下(你也可以通过nuget 安装) http://logging.apache.org/log4net/download_log4net.cgi ...

  4. Python之购物商场

    作业:购物商场 1.流程图 2.初始化用户账号存储文件 初始化存储一个空的用户账号字典,保存到文件 user.pkl.执行如下代码,即可初始化完成. #!/usr/bin/env python # - ...

  5. 字节流之文件输出流FileOutputStream

    文件拷贝:

  6. Priceless Notes

    [Priceless Notes] 1.人类对价格的绝对值没有准确的判断,但是价格或物体的相对值有较准确的判断. 2.物理强度与主观体验的关联成幂曲线.如60瓦的灯会让人觉得亮,但要让人觉得2倍亮的话 ...

  7. SpringMVC总结二:Controller的请求映射方式(RequestMapping)简单介绍

    在SpringMVC总结一:快速入门的基础上简单介绍一下请求映射的方式: 1,标准映射规则 1. @RequestMapping可以设置在类上,也可以设置在方法上 2. 请求的映射规则是:类上的Req ...

  8. 【bzoj2460】[BeiJing2011]元素

    2460: [BeiJing2011]元素 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 692  Solved: 372[Submit][Statu ...

  9. Java 实现分页功能

    driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/test?allowMultiQueries=true&useUnic ...

  10. c语言实践:求两个数的最大公约数

    我的思路是这样的:比如12和16这两个数.先理解一下概念,什么叫最大公约数.就是12有很多个因数,16也有很多个因数,这两堆因数中有一些重合的因数,在这些重合的因数中找到那个最大的.那么最大公约数一定 ...