Struts2之常量的编写

Struts2之常量的编写
Struts2之常量的编写

上述default.properties的struts.action.extention=action,,的常量表示的含义,页面中访问的/hello.action的后缀名,(要么不写后缀名 /hello ,要么只能写.action的后缀名,不能写成像.do 之类的)

如果要修改后缀名,可以复制常量struts.action.extention,在struts.xml中修改

<struts>

<!--编写常量,或者 value="do"-->
    <!--会覆盖之前default.properties文件中的常量值-->
    <constant name="struts.action.extention" value="do,,"></constant>
<!--包结构-->
    <package name="default" namespace="/" extends="struts-default">
<!--配置Action-->
        <!--/hello.action-->
        <action name="hello" class="com.zst.action.HelloAction" method="sayHello">
            <!--选中suc.jsp 右键 Copy relative path 复制路径-->
            <!--路径的写法:在struts2框架中,不管是转发还是重定向,都不用写项目名-->
            <result name="ok" type="">demo1/suc.jsp</result>
        </action>


    </package>

</struts>

此时,再访问hello.action ,会报错。

需要了解的常量

struts.i18n.encoding=UTF-8---------指定默认的编码集,作用于HttpServletRequest的setCharacterEncoding方法
struts.action.extension=action,--------该属性指定需要Struts2处理的请求后缀,该属性的默认值是action,即所有匹配*.action的请求都有Struts2来处理,如果用户需要指定多个请求后缀,则多个后缀之间用英文逗号(,)隔开
struts.serve.static.browserCache=true-------设置浏览器是否缓存静态内容,默认值是true(生产环境下使用)。开发阶段最好关闭
struts.configuration.xml.reload=false---------当struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false(生产环境下使用)
struts.devMode=false---------开发模式下使用,这样可以打印更详细的错误信息
Struts2之常量的编写

Struts2之常量的编写

Struts2之常量的编写

Struts2之常量的编写

struts的配置文件

在大部分应用里,随着应用规模的增加,系统中Action的数量也会大量增加,导致struts.xml配置文件变得非常臃肿

  • 为了避免struts.xml文件过于庞大,臃肿,提高struts.xml文件的可读性,我们将一个struts.xml配置文件分解成多个配置文件,然后在struts.xml文件中包含其他配置文件
    可以在<package>标签中,使用<include>标签来引入其他的struts_xx.xml的配置文件,例如:
<struts>
	<include file = "struts-part1.xml"/>
	<include file = "struts-part2.xml"/>
</struts>

注意:<include file = "cn/itcast/demo2/struts-part1.xml">