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 >
|
相关推荐
分别介绍了快速搭建Spring Web应用、精通MVC结构、URL映射、文件上传与错误处理、创建Restful应用、保护应用、单元测试与验收测试、优化请求、将Web应用部署到云等内容,循序渐进地讲解了Spring MVC4的开发技巧。...
IDEA 搭建Spring MVC环境示例二,使用maven来搭建(方法二) IDEA 搭建Spring MVC环境示例二,使用maven来搭建(方法二)
搭建spring mvc 工程所需要的Jar包
精通Spring MVC 4 中文
《Spring MVC+MyBatis开发从入门到项目实战》分为4篇。第1篇是Java开发环境的搭建,包括JDK的下载与安装、环境变量的配置、MyEclipse的下载与基本配置。第2篇是MyBatis技术入门,包括剖析JDBC的弊端、MyBatis的背景...
Spring MVC MyBatis开发从入门到项目实战
Eclipse 搭建Spring 开发环境
Maven搭建spring mvc环境,应用spring3.2.2 jar包, 代码中包含有测试例子、配置文件等,非常好的一个实例。 希望大家喜欢。
IDEA 搭建Spring MVC环境示例,使用springmvc的插件来搭建(方法一) IDEA 搭建Spring MVC环境示例,使用springmvc的插件来搭建(方法一)
spring mvc 环境搭建实例 spring mvc
本文档主要是springmvc+spring+hibernate框架的搭建,文中带有一个实例dome,以供参考
使用maven简单搭建Spring mvc + redis缓存 个人实验成功
Maven+Spring+Spring MVC+MyBatis+MySQL,搭建SSM框架环境
搭建spring mvc + hibernate
spring MVC环境搭建 所需jar包 ├── commons-logging-1.1.1.jar ├── jstl.jar ├── spring-aop-4.3.0.RELEASE.jar ├── spring-aspects-4.3.0.RELEASE.jar ├── spring-beans-4.3.0.RELEASE.jar ├...
Spring是个非常非常非常优秀的java框架,主要是用它的IOC容器帮我们依赖注入和管理一些...现在我们就来搭建一个利用Spring和Spring MVC结合的web工程最佳实践的例子。以Spring Framework 4.2.0为例,IDE为Myeclipse。
spring mvc
Mastering Spring MVC 4(2015.09)源码