Struts(2) Struts2 详细配置

               Struts2的配置  

            全局配置:

配置在packe中,所有action的上面。

<global-results>

<result name="名字">/页面</result>

    <result name="名字">/页面</result>

</global-results>

局部结果优先级高于全局。

异常信息配置:

<global-exception-mappings>

<exception-mapping result="error" exception="java.lang.

Exception" />

</global-exception-mappings>

404异常、500异常(web.xml配置)

<error-page>

   <error-code>404</error-code>

   <location>/error.jsp</location>

</error-page>

  

<error-page>

   <error-code>500</error-code>

   <location>/error.jsp</location>

</error-page>

          包(package)配置:

所有的action配置,都必须在包中。

<package name=”mypk” extends=”struts-default” namespace=”/”>

 

<action name=”” class=”” method=””>

 

      <result name=”” type=””>/jsp页面路径</result>

 

</action>

 

</package>

 

注意:Action中的name属性可以使用模糊匹配。使用“*

      一般规则:name=“名字_*”  method=”{1}”

示例:<action name="user_*" class="com.zuxia.action.UserInfoAction" method="{1}" />

动态方法调用:根据用户的请求地址,调用指定的方法。

语法规则:action!方法名.action

<result name=””  type=”默认|redirect|redirectAction”>

默认—— 表示内部跳转

redirect —— 外部跳转

redirectAction —— 跳转到指定的Action(必须设置两个参数:namespaceactionName

                                   注意:<action method=”默认方法execute”>   <result name=”默认为success”>

 

 

 

 

            系统常量配置(环境配置):

<constant name=”常量名” value=”常量值” />

所有struts的常量:struts2-core-x.x.x.jar 包中的default.properties

struts.i18n.encoding=UTF-8  系统编码

struts.objectFactory = spring  struts与spring框架结合时设置

struts.devMode = false   启用struts的调试信息(详细更详细的错误信息)

struts.multipart.maxSize=2097152   设置文件上传大小

struts.custom.i18n.resources=资源文件名  国际化时,指定资源文件

posted @ 2012-11-17 22:07  全力以赴001  阅读(234)  评论(0编辑  收藏  举报