spring mvc中 一个完整的 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">
<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>



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值