struts2应用02

来源:互联网 发布:原油数据影响大吗 编辑:程序博客网 时间:2024/06/05 15:07

上节我们完成简单的配置,了解了struts2框架工作流程,本节我们介绍一些action中元素,拦截器等

1.在struts之间引入<constant name="struts.devMode" value="true" /> 

可以打印出更详细的错误信息,改这个文件中的配置就不用去重启tomcat,把它设置为开发模式,发布时要设置为false

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

不希望struts2模板内容对你的开发有影响

3.<constant name="struts.multipart.maxSize" value="10000000"/>

文件上传大小,10M

4.package元素

struts在设计时就考虑到了模块问题,所以把各个动作组织成不同的包。一个典型的struts.xml文件可以有一个或者多个包。

5.拦截器相关元素

必须现在<interceptors>中定义子元素<interceptor>注册一个或多个拦截器,interceptor-stack用于将定义拦截器分组,name自定义,如果动作标签没有指定任何拦截器,则会使用默认default-interceptor-ref该标签指定的拦截器或者拦截器组

<interceptors>
            <interceptor name="loginInterceptor" class="com.tangjiu.detail.tools.interceptor.LoginInterceptor"/>
            <interceptor name="authInterceptor" class="com.tangjiu.detail.tools.interceptor.AuthInterceptor"/>
            <interceptor name="exceptionInterceptor" class="com.tangjiu.detail.tools.interceptor.ExceptionInterceptor"/>

             

                <interceptor-stack name="invoceInterceptor">

                <interceptor-ref name="exceptionInterceptor"/>
                <interceptor-ref name="loginInterceptor"/>
                <interceptor-ref name="authInterceptor"/>
                <interceptor-ref name="defaultStack"/>
            </interceptor-stack>

      

 </interceptors>

<default-interceptor-ref name="invoceInterceptor"></default-interceptor-ref>

6.result元素

<result>元素是<action>的一个子元素它告诉struts你想在动作把权交到哪里

7.<global-results>

一个action可以包含一个<global-results>元素,定义结果是一些通用的结果,如果某个动作在它声明的动作里找不到对应指令,就会搜索该元素中定义结果。

8.通配符映射

“*”为struts2中通配符

例如<action name="emp_*" class="empAction" method="{1}">

emp_login,emp_list等都会匹配到,并到empAction中找到对应login,list等方法



原创粉丝点击