spring mvc中 一个完整的 web.xml配置,包括自定义友好提示页面
2014-03-12 16:03
543 查看
<?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">
<welcome-file-list>
<!-- <welcome-file>/user/list.shtml</welcome-file> -->
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:fuleehaofangjia-context.xml</param-value>
</context-param>
<!-- load spring parent container classpath:spring-context.xml -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--配置编码 filter -->
<filter>
<filter-name>EncodingFilter</filter-name>
<filter-class>com.cn.fuleehaofangjia.web.filter.EncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>EncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 将session的有效时间设置为10分钟 -->
<session-config>
<session-timeout>10</session-timeout>
</session-config>
<servlet>
<servlet-name>fuleehaofangjia</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>fuleehaofangjia</servlet-name>
<url-pattern>*.shtml</url-pattern>
</servlet-mapping>
<!-- 友好提示页面 -->
<!-- 404 页面不存在错误 -->
<error-page>
<error-code>404</error-code>
<location>/publicpart/error404.jsp</location>
</error-page>
<!-- 500 服务器内部错误 -->
<error-page>
<error-code>500</error-code>
<location>/publicpart/error500.jsp</location>
</error-page>
<!-- java.lang.Exception异常错误,依据这个标记可定义多个类似错误提示 -->
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/publicpart/error500.jsp</location>
</error-page>
<!-- java.lang.NullPointerException异常错误,依据这个标记可定义多个类似错误提示 -->
<error-page>
<exception-type>java.lang.NullPointerException</exception-type>
<location>/publicpart/error500.jsp</location>
</error-page>
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/publicpart/error500.jsp</location>
</error-page>
</web-app>
下面是:web-INF下的 项目名-servlet.xml配置文件的内容,自动加载
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 自动装配的业务类必须指定要装配的类所处的包 -->
<context:component-scan base-package="com.cn.fuleehaofangjia.web.controller" />
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="cacheSeconds" value="0" />
<!-- JSON对象转换器 -->
<property name="messageConverters">
<list>
<bean
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
</list>
</property>
</bean>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
<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">
<welcome-file-list>
<!-- <welcome-file>/user/list.shtml</welcome-file> -->
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:fuleehaofangjia-context.xml</param-value>
</context-param>
<!-- load spring parent container classpath:spring-context.xml -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--配置编码 filter -->
<filter>
<filter-name>EncodingFilter</filter-name>
<filter-class>com.cn.fuleehaofangjia.web.filter.EncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>EncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 将session的有效时间设置为10分钟 -->
<session-config>
<session-timeout>10</session-timeout>
</session-config>
<servlet>
<servlet-name>fuleehaofangjia</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>fuleehaofangjia</servlet-name>
<url-pattern>*.shtml</url-pattern>
</servlet-mapping>
<!-- 友好提示页面 -->
<!-- 404 页面不存在错误 -->
<error-page>
<error-code>404</error-code>
<location>/publicpart/error404.jsp</location>
</error-page>
<!-- 500 服务器内部错误 -->
<error-page>
<error-code>500</error-code>
<location>/publicpart/error500.jsp</location>
</error-page>
<!-- java.lang.Exception异常错误,依据这个标记可定义多个类似错误提示 -->
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/publicpart/error500.jsp</location>
</error-page>
<!-- java.lang.NullPointerException异常错误,依据这个标记可定义多个类似错误提示 -->
<error-page>
<exception-type>java.lang.NullPointerException</exception-type>
<location>/publicpart/error500.jsp</location>
</error-page>
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/publicpart/error500.jsp</location>
</error-page>
</web-app>
下面是:web-INF下的 项目名-servlet.xml配置文件的内容,自动加载
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 自动装配的业务类必须指定要装配的类所处的包 -->
<context:component-scan base-package="com.cn.fuleehaofangjia.web.controller" />
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="cacheSeconds" value="0" />
<!-- JSON对象转换器 -->
<property name="messageConverters">
<list>
<bean
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
</list>
</property>
</bean>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
相关文章推荐
- 错误提示web.xml定义错误或异常页面的友好界面显示
- web.xml 配置404和500错误的自定义页面
- web.xml 配置404和500错误的自定义页面
- web.xml 配置404和500错误的自定义页面
- web.xml 配置404和500错误的自定义页面
- 关于web.xml中配置404错误跳转页面 在ie不能显示自定义错误页面的问题
- web.xml 文件中一般包括 servlet, spring, filter, listenr的配置。那么他们是按照一个什么顺序加载呢?
- web.xml 配置404和500错误的自定义页面
- web.xml 配置404和500错误的自定义页面
- web.xml 配置404和500错误的自定义页面
- 关于web.xml中配置404错误跳转页面 在ie不能显示自定义错误页面的问题
- Css-Xml-Xhtml | 为自己的访问者提供一个打印机友好的Web页面
- tomcat 可以在web.xml当中配置404 自定义错误页面
- web.xml页面配置参数详解
- web.xml中配置错误页面不能跳转
- Spring MVC的web.xml配置详解(转)
- 使用web.xml配置Web应用之初始化和预加载servlet和JSP页面
- Spring MVC的web.xml配置详解
- Spring MVC的web.xml配置详解
- 谷歌验证码非web.xml非servlet拦截 使用配置文件自定义加载,防止多次点击(防js攻击)