javaWeb快速开发必备(一 web/struts配置)(ctrl+c,ctrl+v)

 1.<!-- 配置Struts2的核心过滤器 -->
	<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>/*</url-pattern>
	</filter-mapping>
   2.<!-- 配置Spring的监听器,用于初始化ApplicationContext对象 -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext*.xml</param-value>
	</context-param>
   3.<!-- 配置 spring 的 OpenSessionInView 过滤器 -->
     <!-- 作用:Hibernate允许对象关联对象,属性进行延迟加载,若service层返回了一个启用延迟加载功能的领域对象给
                 web层,然后web层访问到那些需要延迟加载的数据时,hibernate session 关闭,就会出现异常。
		 这个配置用于把一个hibernate session和一个完整的请求过程对应的线程相绑定,目的是为了实现
		 “open session in view”的模式,例如它允许在事务提交之后延迟加载显示所需要的对象-->
	<filter>
		<filter-name>OpenSessionInView</filter-name>
		<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>OpenSessionInView</filter-name>
		<url-pattern>*.action</url-pattern>
	</filter-mapping>
   4.<!-- session超时定义,单位为分钟 -->
	<session-config>
		<session-timeout>120</session-timeout>
	</session-config>
   5.struts.xml
       <?xml version="1.0" encoding="UTF-8" ?>
	<!DOCTYPE struts PUBLIC
		"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
		"http://struts.apache.org/dtds/struts-2.3.dtd">
	<struts>
                <!-- 配置扩展名为action -->
		<constant name="struts.action.extension" value="action" />

		<!-- 配置为开发模式 -->
		<constant name="struts.devMode" value="false" />
		
		<!-- 配置主题为simple 默认为(xhtml) -->
		<constant name="struts.ui.theme" value="simple" />

		<!-- struts动态方法调用开启 -->
		<constant name="struts.enable.DynamicMethodInvocation" value="true" />
		<!-- 上传文件最大限量 -->
		<constant name="struts.multipart.maxSize" value="200000000"/>
		<package name="demo" namespace="/" extends="struts-default">
			<interceptors>
				<!-- 声明一个拦截器 -->
				<interceptor name="xxxxInterceptor" class="com.xx.xx"></interceptor>
				<!-- 重新定义defaultStack拦截器栈,需要先判断权限 -->
				<interceptor-stack name="defaultStack">
					<interceptor-ref name="demo" />
					<interceptor-ref name="defaultStack" />
				</interceptor-stack>
			</interceptors>
			<global-results>
				<result name="login">/WEB-INF/jsp/login.jsp</result>
				<result name="toIndex" type="redirect">/index.jsp</result>
			</global-results>
		</package>
		<!-- 加载其他的struts配置文件 -->
		<include file="struts_xx.xml"/>
	</struts>

猜你喜欢

转载自mxl421204733.iteye.com/blog/2281043