struts.xml的作用
struts.xml 为Struts 2的核心配置文件。struts.xml文件主要负责管理应用中的Action映射,以及该Action包含的Result定义等。
struts.xml中主要配置Struts项目的一些全局的属性,用户请求和响应Action之间的对应关系,以及配置Action中可能用到的参数,以及处理结果的返回页面。还包括各种拦截器的配置等。
?
例子:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
??? "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
?<package name="default" extends="strongmvc-default">
??<!-- 基于jasperreport报表结果,jfreechart图表结果,增加jasper,chart -->
??<result-types>
??? ??<result-type name="jasper" />
????<interceptor-ref name="defaultStack" />
????<interceptor-ref name="exceptionInterceptor">
?????<param name="bundlePath">resource.Message</param>
????</interceptor-ref>
???</interceptor-stack>
??</interceptors>
??
??-->
??<interceptors>
???<interceptor-stack name="DemoStack">
????<!--<interceptor-ref name="StrongMVCStack" />
????<interceptor-ref name="defaultStack" />-->
????<interceptor-ref name="store">
? ??????<param name="operationMode">AUTOMATIC</param>
???? ?</interceptor-ref>
???? ?<interceptor-ref name="paramsPrepareParamsStack" />
????<interceptor-ref name="exceptionInterceptor">
?????<param name="bundlePath">com.strongit.uums.resource.Message</param>
????</interceptor-ref>
???</interceptor-stack>
??</interceptors>
??
??<default-interceptor-ref name="DemoStack" />
??<action name="basePrivil1" type="chain">
???????????? <param name="actionName">basePrivil</param>
???????????? <param name="method">priviltree</param>
???????? </result>
??? ?</action>
??? ?<action name="orgmanage1" type="chain">
???????????? <param name="actionName">orgmanage</param>
???????????? <param name="method">tree</param>
???????? </result>
??? ?</action>
??? ?<action name="baseGroup1" type="chain">
???????????? <param name="actionName">baseGroup</param>
???????????? <param name="method">groupTree</param>
???????? </result>
??? ?</action>
??<action name="report_*" method="report">
???<result name="report" type="jasper">
????<param name="location">
?????/WEB-INF/jsp/workflowreport/jasperfile/jasper_template.jasper
????</param>
????<param name="dataSource">processTypeDataList</param>
????<param name="format">{1}</param>
???</result>
???<result name="notdate" type="jasper">
????<param name="location">
?????/WEB-INF/jsp/workflowreport/jasperfile/jasper_notdate.jasper
????</param>
????<param name="dataSource">processTypeDataList</param>
????<param name="format">{1}</param>
???</result>
??</action>
??<action name="chart" method="chart">
???<result name="chart" type="chart">???
????<param name="width">650</param>
????<param name="height">370</param>
???</result>
??</action>
??
?</package>
</struts>