Struts的常量与全局配置

来源:互联网 发布:二十二知乎 编辑:程序博客网 时间:2024/06/07 00:26

转自: http://blog.csdn.net/qq_35448976/article/details/60580828

Struts常量

Struts中默认访问后缀:

Struts1中默认访问后缀是*.do

Struts2中默认访问后缀是*.action

 

如何修改默认访问后缀

1、Struts2.action访问后缀在哪里定义?

Struts-core-2.3.4-1.jar/org.apache.struts/default.propertles

Struts.action.extendsion=action..

2、struts.xml中通过常量修改

<constant name=”struts.action.extension” value=”action,do,”></constant>

指定访问后缀为action/do/没有访问后缀都可以

 

Value=”action,do,”    访问后缀:action/do/不带后缀

Value=”action,do”   访问后缀:actiondo

Value=”action” 访问后最:action

 

 

常量:

   a、 指定默认编码集,作用于HttpServletRequestsetCharacterEncoding方法 和freemarker velocity的输出(post有效)

<constant name="struts.i18n.encoding" value="UTF-8"/>

 

    b、自定义后缀修改常量

<constant name="struts.action.extension" value="do"/>

 

    c、设置浏览器是否缓存静态内容,默认值为true(生产环境下使用),开发阶段最好关闭

<constant name="struts.serve.static.browserCache" value="false"/>

 

    d、struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false(生产环境下使用),开发阶段最好打开

<constant name="struts.configuration.xml.reload" value="true"/>

 

    e、开发模式下使用,这样可以打印出更详细的错误信息

<constant name="struts.devMode" value="true" />

 

 

    f、默认的视图主题

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

 

    g、spring集成时,指定由spring负责action对象的创建

<constant name="struts.objectFactory" value="spring" />

 

 

    h、该属性设置Struts 2是否支持动态方法调用,该属性的默认值是true。如果需要关闭动态方法调用,则可设置该属性为 false

<constant name="struts.enable.DynamicMethodInvocation" value="true"/>

作用:

当我们配置**.xml文件的action时,可以不配置method,可以直接通过访问地址访问指定的method

如:

我问需要访问hello-->login()

方法一:配置method

http://localhost:8080\StrutStu\hello

方法二:通过动态方法访问

http://localhost:8080\StrutStu\hello!login

 

    i、上传文件的大小限制

<constant name="struts.multipart.maxSize" value=“10701096"/>

 

 

配置全局跳转视图

  1. <!--  配置全局跳转视图  -->  
  2.         <global-results>  
  3.             <result name="login">/success.jsp</result>  
  4.         </global-results>  
  5.         <action name="hello" class="cn.lfsenior.c_config.HelloWord" method="login" >  
  6.             <!-- 返回结果标记login对应的页面在当前action中没有配置  
  7.                  所以会去找全局配置是否有login标记对应的页面  
  8.              -->  
  9.         </action>  

配置各项默认值

  1. <!-- 配置各项默认值 -->  
  2.          <!--   
  3.              name  只配置了访问路径名称  
  4.              class 默认执行的action在struts-default有配置  
  5.              <default-class-ref class="com.opensymphony.xwork2.ActionSupport" />  
  6.              method  默认为execute  
  7.              默认的方法execute返回值为success,对应的页面去全局视图找。  
  8.                
  9.           -->  
  10.          <action name="test"></action>  
  11.           
  12.         <!-- 什么情况不配置class? 即处理的aciton -->  
  13.         <!-- 答案: 当只是需要跳转到WEB-INF下资源的时候。(WEB-INF下的资源只对服务端开发,不对客户端开发。所以只能通过转发访问,不能通过重定向访问) -->  
  14.          <action name="test2">  
  15.             <result name="success" type="redirect">/WEB-INF/index.jsp</result>  
  16.          </action>  
原创粉丝点击