`

struts2常量配置

阅读更多
2.struts.xml文件配置

只挑选几个重要的常量说明:

(1) <constant name="struts.locale" value="zh_CN"/>
      <constant name="struts.i18n.encoding" value="UTF-8"/>

      struts2.x[flash=200,200][/flash]  现在只需要一个struts.xml文件就可以了。以前配struts.locale=zh_CN,struts.i18n.encoding=UTF-8,应用起动时会报一个警告,说没有配置locale,必须要在struts.properties里面配置才不会报错,现在这个问题已经解决了,所有配置都可以在xml文件中指定了。


(2) <constant name="struts.action.extension" value="action,do,,"/>

      扩展名可以指定为空。这样地址栏比较好看。但也会有个问题,就是一些其他servlet映射,如cxf,我们会映射地址为/services/*,现在这个地址也变成struts2控制范围的地址了,如果按默认的配置会报找不到action的错误。解决办法是修改mapper类。这在以后文章中会提到。

(3)  <constant name="struts.enable.DynamicMethodInvocation" value="true"/>
       <constant name="struts.enable.SlashesInActionNames" value="true"/>

      开启动态方法。要实现零配置,就是需要动态方法调用。开启action名称可以有 “/”,一个请求地址有多个“/”,struts2就不会再使用类路径扫描的命名空间,只会使用配置的名称。所以既想action名称里使用“/”,又想用struts2默认搜索的命名空间,只能自己修改一下convention插件的实现类了。


(4) <constant name="struts.ui.theme" value="simple"/>

      不用dojo的及struts2复杂标签样式的就把主题设置为simple,这样可以不加载多余的模板。


(5) <constant name="struts.devMode" value="true"/>
      <constant name="struts.i18n.reload" value="true"/>
      <constant name="struts.configuration.xml.reload" value="true"/>
      <constant name="struts.convention.classes.reload" value="true" />

       开启开发者模式,在平时开发时修改action的annotation配置可以不重启,但是修改struts.xml文件还是要重启。修改类的具体内容,debug模式下可以不重启,或是使用javarebel,这个不在讨论范围。


(6)  <constant name="struts.convention.result.path" value="/WEB-INF/pages/"/>

      指定结果页面路径。 convention插件会自动在此路径中寻找文件。放到WEB-INF的目的的保护文件资源,只能通过程序内部跳转才能访问,我们的权限拦截器或其他权限处理只要加到action上就可以了。


(7) <constant name="struts.convention.action.suffix" value="Action"/>
     <constant name="struts.convention.action.name.lowercase" value="true"/>
     <constant name="struts.convention.action.name.separator" value="_"/>

     一个action名字的获取。比如为HelloWorldAction。按照配置,actionName为hello_world。


(8)<constant name="struts.convention.action.disableScanning" value="false"/>

     是否不扫描类。一定要设为false,否则convention插件不起作用,零配置也没有意义。


(9)<constant name="struts.convention.default.parent.package" value="default"/>

     设置默认的父包,一般我们都设置一个default包继承自struts-default。大部分类再继承default。如果有特殊的类需要特殊的包,只能在action中再指定父包了。


(10) <constant name="struts.convention.package.locators" value="action"/>
       <constant name="struts.convention.package.locators.disable" value="false"/>
       <constant name="struts.convention.package.locators.basePackage" value=""/>

   确定搜索包的路径。只要是结尾为action的包都要搜索。basePackage按照默认不用配置,如果配置,只会找以此配置开头的包。locators及locators.basePackage都是一组以逗号分割的字符串。


(11)  <constant name="struts.convention.exclude.packages" value="org.apache.struts.*,org.apache.struts2.*,org.springframework.web.struts.*,org.springframework.web.struts2.*,org.hibernate."/>

   排除哪些包不搜索。按默认配置即可。逗号分割字符串。


(12)  <constant name="struts.convention.action.includeJars" value="" />

   包括哪些jar包中的action。逗号分割字符串。


(13)<constant name="struts.convention.relative.result.types" value="dispatcher,freemarker,velocity"/>

   默认返回的结果类型搜索。按顺序先找相关的dispatcher的jsp文件是否存在。然后再找freemarker,再找velocity。


(14)<constant name="struts.convention.result.flatLayout" value="true"/>

      如果此值设为true,如果一个action的命名空间为/login,名称为HelloWorldAction。result返回值是success,默认会找到/WEB-INF/pages/login/hello_world.jsp(如果有hello_world_success.jsp就找这个文件,连接符“_”是在<constant name="struts.convention.action.name.separator" value="_"/>中配置的)。如果有一个action的result返回值是“error”,就会找/WEB-INF/pages /login/hello_world_error.jsp。

      如果此值设为false,如果一个action的命名空间为/login,名称为HelloWorldAction。result返回值是success,默认会找到/WEB- INF/pages/login/hello_world/index.jsp(如果有success.jsp就找这个文件)。如果有一个action的result返回值是“error”,就会找/WEB-INF/pages /login/hello_world/error.jsp。


(15) <constant name="struts.convention.action.mapAllMatches" value="false"/>
       <constant name="struts.convention.action.checkImplementsAction" value="false"/>
    <constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
    <constant name="struts.convention.redirect.to.slash" value="true"/>

      这几个配置没有太多的实际意义,本着最小检查的原则就可以。


(16)默认拦截器配置,已经简化了许多,一般不需要chain和 fileupload。modelDriven也没什么用,如果我们要使用restfull插件会有用。其实最简单只要一个params就可以了。我加入 exception是为了开发时的异常。servletConfig是为了包装一下request,reponse等对象,staticParams是为了可以配置${}形式参数。actionMappingParams是struts2.1新增的,我初步认为是可以在action配置中传参数,这个还有些疑问。
分享到:
评论

相关推荐

    struts2常量设置详解 struts2常量设置详解

    struts.properties文件中的每一个常量都有详细的介绍

    Struts2的常量配置

    本资源详细讲解了一些Struts2中的常量配置。

    Struts2配置精要之常量constant配置详解(包括零配置Convention 的常量)

    NULL 博文链接:https://chouyi.iteye.com/blog/1562682

    Struts2快速学习步骤

    本章学习目标  struts2 的概念和作用  struts2 的HelloWorld  简单分析struts2 的运行流程  struts2 配置文件加载 ... struts2 常量文件修改  Action 动作类的三种写法  Action 动作类的三种访问方式

    Spring注解配置中间层供Struts2使用

    Spring注解配置中间层供Struts2使用 1.spring通过注解方式生成中间层 2.不使用Struts2的常量struts.objectFactory也可识别中间层

    Struts2入门教程(全新完整版)

    7.开启struts2自带的开发模式常量 6 8.vo传参模式 7 9.ModerDriven传参模式(不建议采用) 7 10.为什么要使用struts2代替struts1.x 7 二、struts.xml配置及例程 7 1.配置文件的优先级 7 2.配置形式 8 3.package配置...

    struts1和struts2的区别

    另外,按照惯例,在Struts1.x中只有“execute”方法能调用Action, 但在Struts2中并非必要,任何声明为public String methodName() 方法,都能通过配置来调用Action。 最后,和Struts1.x最大的革命性的不同是,...

    strtus2常量

    struts2常量的配置说明

    Struts2 in action中文版

    第1章 Struts 2:现代Web框架 2 1.1 Web应用程序:快速学习 2 1.1.1 构建Web应用程序 2 1.1.2 基础技术简介 3 1.1.3 深入研究 6 1.2 Web应用程序框架 7 1.2.1 什么是框架 7 1.2.2 为什么使用框架 8 1.3 Struts 2框架...

    Struts2的struts.xml配置详细介绍

    配置常量,可以改变Struts 2框架的一些行为 name属性表示常量名称,value属性表示常量值 package元素: 包的作用:简化维护工作,提高重用性 包可以“继承”已定义的包,并可以添加自己包的配置 name属性为必须去且...

    struts框架介绍

    struts入门基础,适合零基础的人员学习,介绍了struts的基本配置,struts中常量的介绍,struts获取请求参数,struts类型转换等等

    web页面模块化异步渲染struts-gpipe.zip

     第一个配置的struts常量是配置groovy脚本的的路径, 这个路径可以相对resource目录,第二个配置是需要使用struts-gpipe的package需要继承gpipe-defaule的配置,第三 个配置表示一种struts的返回类型。struts-g...

    struts2的学习笔记+测试源代码

    属性注入-修改请求后缀名--常量配置 博文链接:https://wuzhaohuixy-qq-com.iteye.com/blog/710102

    sshz中文乱码解决方法

    1.在struts.xml文件中加入一个常量配置: &lt;struts&gt; &lt;constant name="struts.i18n.encoding" value="GBK"/&gt; &lt;/struts&gt; 2.在web.xml文件中struts的filter之前加入 &lt;filter&gt; &lt;filter-name&gt;encodingFilter...

    java后台框架源码

    action:存放struts2控制类的包 dao:数据库访问封装 enm:系统中使用到的常量包,这里不是用的常量,用的是枚举替代常量 entity:hibernate对应的orm与数据库表一一对应的实体类 filter:Log4jFormatFilter(格式化...

    Spring的学习笔记

    四、 struts的读常量: 43 第十二课:DTO、VO 43 一、 DTO 43 二、 VO 43 第十二课:SSH整合存在的问题 43 一、 Jsp中访问Session时,Session已经关闭 43 二、 如果不配置事务,openSessionView出现异常 44 三、 ...

    spring2.5 学习笔记

    四、 struts的读常量: 43 第十二课:DTO、VO 43 一、 DTO 43 二、 VO 43 第十二课:SSH整合存在的问题 43 一、 Jsp中访问Session时,Session已经关闭 43 二、 如果不配置事务,openSessionView出现异常 44 三、 ...

    Java学习笔记-个人整理的

    {3.3}String常量重利用}{70}{section.3.3} {3.4}正则表达式}{71}{section.3.4} {3.5}StringBuffer}{75}{section.3.5} {3.6}StringBuilder}{76}{section.3.6} {3.7}StringBuilder与StringBuffer的缺点}{76}{...

    Java加载properties文件实现方式详解

    主要介绍了Java加载properties文件实现方式详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

Global site tag (gtag.js) - Google Analytics