您的位置:首页 > 编程语言 > Java开发

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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: