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}