SSH框架之Struts的默认访问后缀、相同访问路径问题、常量

来源:互联网 发布:y2y的网络意思 编辑:程序博客网 时间:2024/06/16 13:19

一、Struts中默认访问后缀:
1、Struts1中默认访问后缀是*.do
2、Struts2中默认访问后缀是*.action

3、如何修改默认访问后缀:
1)Struts2的.action访问后缀在哪里定义?
Struts-core-2.3.4.1.jar/org.apache.struts/default.properties中的

struts.action.extension=action,,

2)在struts.xml中进行对常量的修改
所有的项目都要使用,是一个全局配置,所以位置应该位于:
<struts>标签的后面,<package>标签的前面!

<!--指定访问后缀为action/do/没有访问后缀,都可以--><constant name="struts.action.extension" value="action,do,"></constant>

4、情况分析

value="action,,"    localhost:8080/struts_02/user_register          OK    localhost:8080/struts_02/user_register.action   OKvalue="action,"value="action"    localhost:8080/struts_02/user_register.action   OKvalue="action,do,"    localhost:8080/struts_02/user_register          OK    localhost:8080/struts_02/user_register.do       OK    localhost:8080/struts_02/user_register.action   OKvalue="action,do"    localhost:8080/struts_02/user_register.do       OK    localhost:8080/struts_02/user_register.action   OK

二、相同访问路径问题
问题产生:
1、Action

2、struts.xml

<action name="user_*" class="sram.config.UserAction4" method="{1}">    <result name="success">/index.jsp</result></action><action name="user_*" class="sram.config2.UserAction" method="{1}">    <result name="success">/index.jsp</result></action>

3、由于上述情况,所以二者想要访问register方法的访问路径均为:
http://localhost:8080/struts_02/user_register

结果:
当我们访问此路径时,运行情况到底如何?

由此可见,配置在前面的会被配置在后面的覆盖掉

三、Struts中的常量(Struts-core-2.3.4.1.jar/org.apache.struts/default.properties中)
1、详解:

<!--指定默认编码集,作用于HttpServletRequest的setCharacterEncoding方法 和freemarker 、velocity的输出(仅对POST起作用)--><constant name="struts.i18n.encoding" value="UTF-8"/><!--自定义后缀修改常量--><constant name="struts.action.extension" value="do"/><!--设置浏览器是否缓存静态内容,默认值为true(生产环境下使用),开发阶段最好关闭 --><constant name="struts.serve.static.browserCache" value="false"/><!--当struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false(生产环境下使用),开发阶段最好打开 --><constant name="struts.configuration.xml.reload" value="true"/><!--开发模式下使用,这样可以打印出更详细的错误信息 --><constant name="struts.devMode" value="true" /><!--默认的视图主题 --><constant name="struts.ui.theme" value="simple" /><!--与spring集成时,指定由spring负责action对象的创建--> <constant name="struts.objectFactory" value="spring" /><!--该属性设置Struts 2是否支持动态方法调用,该属性的默认值是true。如果需要关闭动态方法调用,则可设置该属性为 false--><constant name="struts.enable.DynamicMethodInvocation" value="false"/><!--上传文件的大小限制,value的值为单位字节--><constant name="struts.multipart.maxSize" value=“10701096"/>

2、应用:动态方法调用(不推荐使用,原因:这种形式,需要对程序结构有所了解,不安全)
1、动态方法调用语法:action name+!+方法名
2、举例:

0 0
原创粉丝点击