SpringMVC

  Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring Web Flow里面。Spring 框架提供了构建 Web 应用程序的全功能 MVC 模块。使用 Spring 可插入的 MVC 架构,从而在使用Spring进行WEB开发时,可以选择使用Spring的Spring MVC框架或集成其他MVC开发框架,如Struts1(现在一般不用),Struts 2(一般老项目使用)等。

一、配置web.xml

 
    <servlet> 
        <servlet-name>SpringMVCservlet-name> 
        <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class> 
        <init-param> 
            <param-name>contextConfigLocationparam-name> 
            <param-value>classpath:spring-mvc.xmlparam-value> 
        init-param> 
        <load-on-startup>1load-on-startup> 
        <async-supported>trueasync-supported> 
    servlet> 
    <servlet-mapping> 
        <servlet-name>SpringMVCservlet-name> 
         
        <url-pattern>/url-pattern> 
    servlet-mapping>
View Code

二、配置Spring-mvc.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:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans   
                       http://www.springframework.org/schema/beans/spring-beans-3.1.xsd   
                       http://www.springframework.org/schema/context   
                       http://www.springframework.org/schema/context/spring-context-3.1.xsd   
                        http://www.springframework.org/schema/mvc   
                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
    
    <context:component-scan base-package="com.zml.action" />
 
    
    <bean
        class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <list>
                <ref bean="mappingJacksonHttpMessageConverter" /> 
            list>
        property>
    bean>
     
    
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        
        <property name="prefix" value="/jsp/" />
        <property name="suffix" value=".jsp" />
    bean>
 
    
    <bean id="mappingJacksonHttpMessageConverter"
        class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>text/html;charset=UTF-8value>
            list>
        property>
    bean>
     
    
    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        
        <property name="defaultEncoding" value="utf-8" />
        
        <property name="maxUploadSize" value="10485760000" />
        
        <property name="maxInMemorySize" value="40960" />
    bean>
 
beans> 
View Code

 

你可能感兴趣的:(SpringMVC)