zoukankan      html  css  js  c++  java
  • Struts2 三、指定Struts2处理的请求后缀

    Action的请求通常情况下默认为以.action结尾,例如:http://localhost:9000/Struts2/hello/helloAction_sayHello.action    .action就是这个请求的后缀,在Struts2中这个后缀是可以变更的,方法很简单,首先将Web.xml中的StrutsMapping改成如下代码:

     <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
      </filter>
      <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>


    然后在Struts.xml中添加一个常量:

    <!-- 该属性用于指定Struts2请求处理的后缀,默认为.action 可以处理所有后缀是.action的处理,如果
    	需要指定多个请求处理后缀,后缀之间用逗号隔开 -->
    	<constant name="struts.action.extension" value="do,action"></constant>

    即可,如上代码,如果想实现请求中多个备用的后缀的话,在Value中将多个后缀以逗号分隔。

    下面贴一下,Struts2中最常见的Struts2常量配置:

    <!-- 指定默认 编码集,作用于HttpServletRequest 的setCharacterEncoding方法和freemarker velocity的输出 -->
    	<constant name="struts.118n.encoding" value="UTF-8"></constant>
    	<!-- 该属性用于指定Struts2请求处理的后缀,默认为.action 可以处理所有后缀是.action的处理,如果
    	需要指定多个请求处理后缀,后缀之间用逗号隔开 -->
    	<constant name="struts.action.extension" value="do,action"></constant>
    	<!-- 设置浏览器是否缓存静态内容,默认值为true,开发环境下建议设置为false -->
    	<constant name="struts.serve.static.browserCache" value="false"></constant>
    	<!-- 当Struts 修改文件以后,是否重新加载该文件,默认为false,推荐开发环境下设置为true -->
    	<constant name="struts.configuration.xml.reload" value="true"></constant>
    	<!-- 开发模式下可以打印更详细的错误信息 -->
    	<constant name="struts.devMode" value="false"></constant>
    	<!-- 默认视图主题  -->
    	<constant name="struts.ui.theme" value="simple"></constant>
    	<!-- 与Spring集成是,指定有Spring创建Action对象 -->
    	<constant name="struts.objectFactory" value="spring"></constant>
    </pre><pre>
    
    
    <constant name="struts.enable.DynamicMethodInvocation" value="false"></constant><!-- 禁止调用动态方法 -->
    <!-- 上传文件的大小限制 --><constant name="struts.multipart.maxSize" value="10701096"></constant>



  • 相关阅读:
    初入职场的一些感悟
    疲惫于时间管理术-应该如何把握时间
    何为有效沟通
    powdesigner生成模型以后导入erwin大坑 oracle12c
    oracle 12c下载及安装全解析(踩坑注意)-win64-12102版本-2019-10-17
    聚集索引与非聚集索引的用法举例与使用注意
    十分钟,带你了解MobX 与 React
    GET https://pic.qyer.com/avatar/008/23/22/84/200?v=1469960206 403 (Forbidden) 图片防盗链
    writing
    使用github pages搭建博客
  • 原文地址:https://www.cnblogs.com/raphael5200/p/5114799.html
Copyright © 2011-2022 走看看