码迷,mamicode.com
首页 > 其他好文 > 详细

struts2零配置参考示例

时间:2015-06-26 16:19:36      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:


<filter>
		<filter-name>struts2</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>*.action</url-pattern>
		<url-pattern>*.jsp</url-pattern>
		<dispatcher>REQUEST</dispatcher>
		<dispatcher>FORWARD</dispatcher>
	</filter-mapping>


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
        "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
    <constant name="struts.devMode" value="false"/> 
    <constant name="struts.i18n.reload" value="false"/>
    <constant name="struts.configuration.xml.reload" value="false"/> 
    <constant name="struts.convention.classes.reload" value="false" />
    <!-- <constant name="struts.objectFactory" value="spring" /> -->
    <constant name="struts.ui.theme" value="simple"/>
    <constant name="struts.action.extension" value="action,do"/>
    <constant name="struts.i18n.encoding" value="UTF-8"/>
    <constant name="struts.enable.DynamicMethodInvocation" value="true"/><!--user!login方式为true,user_login通配符为false,零配置使用false会有问题 -->
     <!--struts.convention零配置 -->
     <constant name="struts.convention.action.mapallmatches" value="true"/>
    <constant name="struts.convention.action.suffix" value="Action"/><!-- 扫描以Controller为后缀名的类,值只有一个 -->
    <constant name="struts.convention.action.name.lowercase" value="true"/>
    <constant name="struts.convention.action.name.separator" value="_"/><!--按以上3个配置,比如为HelloWorldController。按照配置,映射的url为hello_world.jsp  -->
    <constant name="struts.convention.result.path" value="/WEB-INF/pages"/><!-- action跳转后视图存放位置 -->
    <constant name="struts.convention.default.parent.package" value="crud-default" /><!-- 默认是default,要使用零配置需要配置成convention-default或者继承它 -->
    <constant name="struts.convention.package.locators" value="controller,action" /><!-- 指定搜寻包的路径 -->
    <constant name="struts.convention.package.locators.basePackage" value="com.thinkmore.business" /><!-- 指定搜寻包的根路径 -->
    <constant name="struts.convention.relative.result.types" value="dispatcher,freemarker,velocity"/><!-- 先找jsp,否则依次查找 -->
    <!-- 用于CRUD Action的parent package,继承了零配置类 -->
    <package name="crud-default" extends="convention-default">
        <!-- 基于paramsPrepareParamsStack,增加store interceptor保证actionMessage在redirect后不会丢失 -->
        <interceptors>
            <interceptor-stack name="crudStack">
                <interceptor-ref name="store">
                    <param name="operationMode">AUTOMATIC</param>
                </interceptor-ref>
                <!-- 顾名思义,这里的paramsPrepareParamsStack调用interceptor顺序是先params然后prepare最后再params,
                而defaultStack是直接prepare然后params
                若Action实现Preparable接口,则Action方法需实现prepare()方法
                 -->
                <interceptor-ref name="paramsPrepareParamsStack" />
            </interceptor-stack>
        </interceptors>
        <default-interceptor-ref name="crudStack" />
    </package>
</struts>


struts2零配置参考示例

标签:

原文地址:http://blog.csdn.net/yaerfeng/article/details/46650995

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!