欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

spring mvc web.xml,servlet-context.xml配置文件示例,,spring web.x

来源: javaer 分享于  点击 20154 次 点评:217

spring mvc web.xml,servlet-context.xml配置文件示例,,spring web.x


spring 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">    <!-- Reads request input using UTF-8 encoding -->    <filter>        <filter-name>characterEncodingFilter</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>        <init-param>            <param-name>forceEncoding</param-name>            <param-value>true</param-value>        </init-param>    </filter>    <filter-mapping>        <filter-name>characterEncodingFilter</filter-name>        <url-pattern>/*</url-pattern>    </filter-mapping>    <!-- Handles all requests into the application -->    <servlet>        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>        <init-param>            <param-name>contextConfigLocation</param-name>            <param-value>                /WEB-INF/spring/appServlet/servlet-context.xml            </param-value>        </init-param>        <load-on-startup>1</load-on-startup>    </servlet>    <servlet-mapping>        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>        <url-pattern>/</url-pattern>    </servlet-mapping></web-app>

servlet-context.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:context="http://www.springframework.org/schema/context"    xmlns:mvc="http://www.springframework.org/schema/mvc"    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">    <!-- Scans the classpath of this application for @Components to deploy as beans -->    <context:component-scan base-package="org.springframework.samples.mvc.basic" />    <!-- Configures the @Controller programming model -->    <mvc:annotation-driven />    <!-- Forwards requests to the "/" resource to the "welcome" view -->    <mvc:view-controller path="/" view-name="welcome"/>    <!-- Configures Handler Interceptors -->        <mvc:interceptors>        <!-- Changes the locale when a 'locale' request parameter is sent; e.g. /?locale=de -->        <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />    </mvc:interceptors>    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources/ directory -->    <mvc:resources mapping="/resources/**" location="/resources/" />    <!-- Saves a locale change using a cookie -->    <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" />    <!-- Application Message Bundle -->    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">        <property name="basename" value="/WEB-INF/messages/messages" />        <property name="cacheSeconds" value="0" />    </bean>    <!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory -->    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">        <property name="prefix" value="/WEB-INF/views/"/>        <property name="suffix" value=".jsp"/>    </bean></beans>

完整的spring mvc示例项目文件

相关栏目:

用户点评