Quickly build Spring MVC 4 Development Environment

Source: Internet
Author: User

Quickly build Spring MVC 4 Development Environment

Spring MVC, as a SpringFrameWork product, has received wide attention from developers since its birth. Now Spring MVC is evolving rapidly in Java. If there are more developers, if you don't know Spring MVC, you may get laughed. Let's not talk about it. Let's first tell you how to build the Spring MVC development environment.

 

(1) Prepare the Work Environment:

JDK 1.7

Eclipse Kepler

For Apache Tomcat 8.0

 

(2) create a Maven project in Eclipse. In the Archetype type, select "maven-archetype-webapp ".

 

(3) Configure pom. xml.

 

   
  
   4.0.0
    
  
   com.favccxx.favsoft
    favspringmvcrestful  
  
   war
    
  
   0.0.1-SNAPSHOT
    
  
   favspringmvcrestful Maven Webapp
    
  
   http://maven.apache.org
        
        
   
    4.1.1.RELEASE
     
       
      
         
    
     junit
          junit      
    
     3.8.1
          
    
     test
        
            
           
    
     org.springframework
            spring-core        
    
     ${spring.version}
        
       
           
    
     org.springframework
            spring-webmvc        
    
     ${spring.version}
        
       
           
    
     org.springframework
            spring-beans        
    
     ${spring.version}
        
       
           
    
     org.springframework
            spring-context        
    
     ${spring.version}
        
            
           
    
     jstl
            jstl        
    
     1.2
        
       
           
    
     taglibs
            standard        
    
     1.1.2
        
          
    
      
   
    favspringmvcrestful
     
  
 

 

(4) Configure Spring MVC forwarding in the WEB-INF/web. xml.

 

 
     
  
   favspringmvcrestful
       
          
   
    encodingFilter
           
   
    org.springframework.web.filter.CharacterEncodingFilter
           
               
    
     encoding
                
    
     UTF-8
            
           
               
    
     forceEncoding
                
    
     true
            
       
      
          
   
    encodingFilter
           
   
    /*
       
       
          
   
    org.springframework.web.context.ContextLoaderListener
       
       
          
   
    springMVC
           
   
    org.springframework.web.servlet.DispatcherServlet
           
               
    
     contextConfigLocation
                
    
     classpath*:spring-context.xml
            
           
   
    1
       
      
          
   
    springMVC
           
   
    /
       
  
 

 

(5) under the resources Directory, create spring-context.xml, support annotation, page path parsing, etc.

 

 
              
           
           
          
           
            
         
     
    
   
  
 


 

(6) create a HelloController class and use annotations to call the Spring MVC class.

 

 

package com.favccxx.favsoft.favjson.controller; import java.util.HashMap;import java.util.Map; import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.servlet.ModelAndView; @Controllerpublic class HelloController {         @RequestMapping(/greeting)    public ModelAndView greeting(@RequestParam(value=name, defaultValue=World) String name) {         System.out.println(Hello  + name);         Map
 
   map = new HashMap
  
   ();         map.put(userName, name);         return new ModelAndView(/hello,map);    }      }
  
 


 

(7) Create/WEB-INF/views/hello. jsp to show data.

 

<%@ page language=java contentType=text/html; charset=UTF-8    pageEncoding=UTF-8%><%@ taglib uri=http://java.sun.com/jsp/jstl/core prefix=c%>
Hello, $ {userName}

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.