spring mvc web.xml dispatcher-servlet.xml配置

标签: spring mvc xml 配置
339人阅读 评论(0) 收藏 举报
分类:

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">


<display-name>edu</display-name>  


    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    
   <!--spring-->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    
     <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> 
    
    <!--springmvc-->
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    
   <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
   
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
  
</web-app>


dispatcher-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:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd">


    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
    <context:annotation-config/> 
    <!--支持json转换器--> 
     <mvc:annotation-driven>  
    <!--     解决返回String时乱码-->  
    <mvc:message-converters register-defaults="true">  
        <bean class="org.springframework.http.converter.StringHttpMessageConverter">  
             <property name="supportedMediaTypes">    
                <list>    
                    <value>text/plain;charset=UTF-8</value>    
                    <value>text/html;charset=UTF-8</value>    
                </list>    
            </property>    
        </bean>  
      </mvc:message-converters>  
    </mvc:annotation-driven>  
    <!--     配置直接转发的页面不用开发控制器-->   
    <mvc:view-controller path="/admin"  view-name="/admin/admin"/>
    <mvc:view-controller path="/regeist"  view-name="/regeist"/>
    <context:component-scan base-package="cn.*" /> 
    <mvc:resources location="/file/" mapping="/file/**" />
    <mvc:resources location="/js/" mapping="/js/**" />
    <mvc:resources location="/css/" mapping="/css/**" />
    <mvc:resources location="/images/" mapping="/images/**" />  
    <mvc:resources location="/easyui/" mapping="/easyui/**" />
    <mvc:resources location="/bootstrap/" mapping="/bootstrap/**" />
     <mvc:resources location="/Flat-UI/" mapping="/Flat-UI/**" />
    <mvc:resources location="/uploadify/" mapping="/uploadify/**" />
    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/jsp/"
          p:suffix=".jsp" />
    
 
</beans>



查看评论

O'Reilly的历史和理念

History & Company OverviewBy Tim OReillyIn the BeginningWeve been in business since 1978, originally...
  • jiangtao
  • jiangtao
  • 2004-04-15 19:52:00
  • 3123

SpringMVC 4.2.2 - Web.xml,Dispatcher-Servlet及ApplicationContext配置笔记

SpringMVC 4.2.2 - Web.xml,Dispatcher-Servlet及ApplicationContext配置笔记   Spring MVC 项目中常用的主要配置项Web.XM...
  • chendev1
  • chendev1
  • 2015-12-14 14:28:12
  • 5853

springmvc系列(二)-自定义dispatcherservlet加载的xml配置文件

上篇博客中,web.xml的配置如下
  • u010372981
  • u010372981
  • 2017-06-30 16:47:27
  • 1259

关于Spring MVC的详细步骤(包括web.xml;applicationContext.xml;dispatcher-servlet.xml)

Spring MVC配置步骤详解: 一:Spring
  • miaomiao870731
  • miaomiao870731
  • 2014-11-06 11:04:25
  • 671

Spring MVC 配置文件dispatcher-servlet.xml 文件详解

  • yanjun008
  • yanjun008
  • 2014-12-25 14:45:25
  • 9552

idea 创建 springMVC 项目中 dispatcher-servlet.xml文件的基本配置

xml version="1.0" encoding="UTF-8"?> xmlns="http://www.springframework.org/schema/beans" xmln...
  • MeGoodtoo
  • MeGoodtoo
  • 2017-06-15 14:59:37
  • 873

spring mvc 配置web.xml servlet.xml文件配置以及出现异常的解决方案

java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not ...
  • tengxing007
  • tengxing007
  • 2015-09-26 09:37:38
  • 997

DispatcherServlet在web.xml中的配置

 DispatcherServlet作用 DispatcherServlet是前端控制器设计模式的实现,提供Spring Web MVC的集中访问点,而且负责职责的分派,而且与Spring I...
  • qq_26154077
  • qq_26154077
  • 2015-04-01 17:04:22
  • 3992

springMvc 配置 controller 配置 spring-dispatcher-servlet.xml

  • Homing_qu
  • Homing_qu
  • 2017-05-24 16:19:35
  • 283

[spring]Spring MVC web.xml 配置文件配置

原文地址:http://www.24xuexi.com/w/2012-03-28/98642.html 新建立一个Web Project, 含有web.xml org.springf...
  • wendellup
  • wendellup
  • 2012-12-07 17:08:50
  • 45704
    个人资料
    持之以恒
    等级:
    访问量: 1万+
    积分: 543
    排名: 9万+