Spring MVC是Spring提供的一个强大而灵活的web框架。借助于注解,Spring MVC提供了几乎是POJO的开发模式,使得控制器的开发和测试更加简单。这些控制器一般不直接处理请求,而是将其委托给Spring上下文中的其他bean,通过Spring的依赖注入功能,这些bean被注入到控制器中。
Spring MVC主要由DispatcherServlet、处理器映射、处理器(控制器)、视图解析器、视图组成。他的两个核心是两个核心:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"><title>Add User From</title></head><body><formaction="save"method="post"><fieldset><legend>创建用户</legend><p><label>姓名:</label><inputtype="text"id="name"name="name"tabindex="1"></p><p><label>年龄:</label><inputtype="text"id="age"name="age"tabindex="2"></p><p><label>密码:</label><inputtype="text"id="pwd"name="pwd"tabindex="3"></p><pid="buttons"><inputid="reset"type="reset"tabindex="4"value="取消"><input
id="submit"type="submit"tabindex="5"value="创建"></p></fieldset></form></body></html>
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
detail.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"><title>Insert title here</title></head><body><divid="gloobal"><h4>创建成功</h4><p><h5>详情:</h5>
姓名:${user.name}<br /> 年龄:${user.age}<br /> 密码:${user.pwd}<br /></p></div></body></html>