1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
< project ?xmlns = "http://maven.apache.org/POM/4.0.0" ?xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
?? xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0?http://maven.apache.org/maven-v4_0_0.xsd" >
?? < modelVersion >4.0.0</ modelVersion >
?? < groupId >com.favccxx.favsoft</ groupId >
?? < artifactId >favspringmvcrestful</ artifactId >
?? < packaging >war</ packaging >
?? < version >0.0.1-SNAPSHOT</ version >
?? < name >favspringmvcrestful?Maven?Webapp</ name >
?? < url >http://maven.apache.org</ url >
?? ???? < properties >
?????? < spring.version >4.1.1.RELEASE</ spring.version >
?? </ properties >
?? ??? < dependencies >
???? < dependency >
?????? < groupId >junit</ groupId >
?????? < artifactId >junit</ artifactId >
?????? < version >3.8.1</ version >
?????? < scope >test</ scope >
???? </ dependency >
???? ????? < dependency >
???????? < groupId >org.springframework</ groupId >
???????? < artifactId >spring-core</ artifactId >
???????? < version >${spring.version}</ version >
???? </ dependency >
???? < dependency >
???????? < groupId >org.springframework</ groupId >
???????? < artifactId >spring-webmvc</ artifactId >
???????? < version >${spring.version}</ version >
???? </ dependency >
???? < dependency >
???????? < groupId >org.springframework</ groupId >
???????? < artifactId >spring-beans</ artifactId >
???????? < version >${spring.version}</ version >
???? </ dependency >
???? < dependency >
???????? < groupId >org.springframework</ groupId >
???????? < artifactId >spring-context</ artifactId >
???????? < version >${spring.version}</ version >
???? </ dependency >
???? ????? < dependency >
???????? < groupId >jstl</ groupId >
???????? < artifactId >jstl</ artifactId >
???????? < version >1.2</ version >
???? </ dependency >
???? < dependency >
???????? < groupId >taglibs</ groupId >
???????? < artifactId >standard</ artifactId >
???????? < version >1.1.2</ version >
???? </ dependency >
???? ??? </ dependencies >
?? < build >
???? < finalName >favspringmvcrestful</ finalName >
?? </ build >
</ project >
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
<? xml ?version = "1.0" ?encoding = "UTF-8" ?>
< web-app ?version = "2.4" ?xmlns = "http://java.sun.com/xml/ns/j2ee"
???? xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
???? xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee?
???? http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
???? < display-name >favspringmvcrestful</ display-name >
?
???? < filter >
???????? < filter-name >encodingFilter</ 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 >encodingFilter</ filter-name >
???????? < url-pattern >/*</ url-pattern >
???? </ filter-mapping >
?
???? < listener >
???????? < listener-class >org.springframework.web.context.ContextLoaderListener</ listener-class >
???? </ listener >
?
???? < servlet >
???????? < servlet-name >springMVC</ servlet-name >
???????? < servlet-class >org.springframework.web.servlet.DispatcherServlet</ servlet-class >
???????? < init-param >
???????????? < param-name >contextConfigLocation</ param-name >
???????????? < param-value >classpath*:spring-context.xml</ param-value >
???????? </ init-param >
???????? < load-on-startup >1</ load-on-startup >
???? </ servlet >
???? < servlet-mapping >
???????? < servlet-name >springMVC</ servlet-name >
???????? < url-pattern >/</ url-pattern >
???? </ servlet-mapping >
</ web-app >
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<? 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/beans?http://www.springframework.org/schema/beans/spring-beans.xsd
???????? http://www.springframework.org/schema/context?http://www.springframework.org/schema/context/spring-context-4.1.xsd
???????? http://www.springframework.org/schema/mvc?http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
???????? ????? < context:component-scan ?base-package = "com.favccxx.favsoft.favjson.controller" ></ context:component-scan >
???? ????? < mvc:annotation-driven ></ mvc:annotation-driven >
???? ????? < bean ?id = "viewResolver" ?class = "org.springframework.web.servlet.view.UrlBasedViewResolver" >
???????? < property ?name = "viewClass"
???????????? value = "org.springframework.web.servlet.view.JstlView" ?/>
???????? < property ?name = "prefix" ?value = "/WEB-INF/views" ?/>
???????? < property ?name = "suffix" ?value = ".jsp" ?/>
???? </ bean >
</ beans >
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
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;
?
@Controller public ?class ?HelloController?{
???? ????? @RequestMapping ( "/greeting" )
???? public ?ModelAndView?greeting( @RequestParam (value= "name" ,?defaultValue= "World" )?String?name)?{
????????? System.out.println( "Hello?" ?+?name);
????????? Map<String,?Object>?map?=? new ?HashMap<String,?Object>();
????????? map.put( "userName" ,?name);
????????? return ?new ?ModelAndView( "/hello" ,map);
???? }
????? ?} |
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<%@?page?language="java"?contentType="text/html;?charset=UTF-8" ???? pageEncoding="UTF-8"%>
<%@?taglib?uri="http://java.sun.com/jsp/jstl/core"?prefix="c"%> <!DOCTYPE?html> < html >
< head >
< meta ?http-equiv = "Content-Type" ?content = "text/html;?charset=UTF-8" >
< title >Hello</ title >
</ head >
< body >
???? 你好,${userName?}
</ body >
</ html >
|
?