首页 > 学院 > 开发设计 > 正文

Struts的常量与全局配置

2019-11-06 06:37:21
字体:
来源:转载
供稿:网友

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”   访问后缀:action或do

Value=”action” 访问后最:action

 

 

常量:

   a、 指定默认编码集,作用于HttpServletRequest的setCharacterEncoding方法 和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"/>

 

 

配置全局跳转视图

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

配置各项默认值

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

 

 

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表