1. 程式人生 > >java web 服務的web.xml詳解

java web 服務的web.xml詳解

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
	<display-name>app</display-name>

	<!-- 載入Spring配置檔案 -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:spring-starter.xml</param-value>
	</context-param>

	<!-- 字符集 過濾器 -->
	<filter>
		<filter-name>encodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>encodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<!-- Spring監聽器 -->
	<listener>
		<description>Spring監聽器</description>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<!-- 防止Spring記憶體溢位監聽器 -->
	<listener>
		<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
	</listener>

	<!-- Spring MVC -->
	<servlet>
		<servlet-name>SpringMVC</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<description>SpringMVC</description>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:spring-starter-conf/spring-mvc.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>SpringMVC</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>

	<!-- 新增監聽器 -->
	<listener>
		<listener-class>com.***.**.***.web.listener.MyAppListener</listener-class>
	</listener>
	<listener>
		<listener-class>com.**.**.**.web.listener.DateInitListener</listener-class>
	</listener>

	<!--2.獲取登入資訊過濾器 -->
	<filter>
		<filter-name>userAuthFilter</filter-name>
		<filter-class>com.****.**.**.web.filter.UserAuthFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>userAuthFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<servlet>
		<servlet-name>DruidStatView</servlet-name>
		<servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
		<init-param>
			<!-- 使用者名稱 -->
			<param-name>loginUsername</param-name>
			<param-value>druid</param-value>
		</init-param>
		<init-param>
			<!-- 密碼 -->
			<param-name>loginPassword</param-name>
			<param-value>dream</param-value>
		</init-param>
	</servlet>
	<servlet-mapping>
		<servlet-name>DruidStatView</servlet-name>
		<url-pattern>/druid/*</url-pattern>
	</servlet-mapping>

	<!-- 後臺異常處理頁面 -->
	<error-page>
		<error-code>404</error-code>
		<location>/404.jsp</location>
	</error-page>
	<error-page>
		<error-code>500</error-code>
		<location>/500.jsp</location>
	</error-page>

	<session-config>
		<session-timeout>30</session-timeout>
	</session-config>

</web-app>