Spring MVC 3.0 深入
核心原理:
. 用户发送请求给服务器。url:user.do
. 服务器收到请求。发现DispatchServlet可以处理。于是调用DispatchServlet。
. DispatchServlet内部,通过HandleMapping检查这个url有没有对应的Controller。如果有,则调用Controller。
. Controller开始执行。
. Controller执行完毕后,如果返回字符串,则ViewResolver将字符串转化成相应的视图对象;如果返回ModelAndView对象,该对象本身就包含了视图对象信息。
. DispatchServlet将执视图对象中的数据,输出给服务器。
. 服务器将数据输出给客户端。
spring3.0中相关jar包的含义:
org.springframework.aop-3.0..RELEASE.jar spring的aop面向切面编程
org.springframework.asm-3.0..RELEASE.jar spring独立的asm字节码生成程序
org.springframework.beans-3.0..RELEASE.jar IOC的基础实现
org.springframework.context-3.0..RELEASE.jar IOC基础上的扩展服务
org.springframework.core-3.0..RELEASE.jar spring的核心包
org.springframework.expression-3.0..RELEASE.jar spring的表达式语言
org.springframework.web-3.0..RELEASE.jar web工具包
org.springframework.web.servlet-3.0..RELEASE.jar mvc工具包
小demo:
web.xml填写:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup></load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/WEB-INF/jsp/index.jsp</welcome-file>
</welcome-file-list>
</web-app>
WEB-INF下的dispatcherServlet-servlet.xml文件填写:
<?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:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"> <!-- 对web包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 -->
<context:component-scan base-package="com.sxt.web"/> <!--对模型视图名称的解析,即在模型视图名称添加前后缀 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp">
<!-- 如果使用jstl的话,配置下面的属性 -->
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
</bean>
</beans>
java文件的代码:
package com.sxt.web; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; @Controller
@RequestMapping(value = "/user")
public class UserController { @RequestMapping(value = "/reg")
public String reg(@RequestParam(value = "uname") String uname) {
System.out.println("HelloController.handleRequest()");
return "index";
} @RequestMapping(value = "/page")
public String page(@RequestParam(value = "page") String page, Model model) {
System.out.println("////////////////////" + page);
model.addAttribute("param", "success");
return page;
}
}
jar包我将所有的spring的lib下的jar都放进去了,如果发现classNotFound的话,挨个添加补充就行了。
Spring MVC 3.0 深入的更多相关文章
- Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解实例详解(四)
这一章大象将详细分析web层代码,以及使用Spring MVC的注解及其用法和其它相关知识来实现控制器功能. 之前在使用Struts2实现MVC的注解时,是借助struts2-conventi ...
- Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解实例详解(二)
在上一篇文章中我详细的介绍了如何搭建maven环境以及生成一个maven骨架的web项目,那么这章中我将讲述Spring MVC的流程结构,Spring MVC与Struts2的区别,以及例子中的一些 ...
- Spring MVC 3.0 返回JSON数据的方法
Spring MVC 3.0 返回JSON数据的方法1. 直接 PrintWriter 输出2. 使用 JSP 视图3. 使用Spring内置的支持// Spring MVC 配置<bean c ...
- CRUD using Spring MVC 4.0 RESTful Web Services and AngularJS
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- spring mvc 3.0 实现文件上传功能
http://club.jledu.gov.cn/?uid-5282-action-viewspace-itemid-188672 —————————————————————————————————— ...
- 解决 spring mvc 3.0 结合 hibernate3.2 使用<tx:annotation-driven>声明式事务无法提交的问题(转载)
1.问题复现 spring 3.0 + hibernate 3.2 spring mvc使用注解方式:service使用@service注解 事务使用@Transactional 事务配置使用 < ...
- Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解实例详解(三)
前两章我为大家详细介绍了如何搭建Maven环境.Spring MVC的流程结构.Spring MVC与Struts2的区别以及示例中的一些配置文件的分析.在这一章,我就对示例的层次结构进行说明,以及M ...
- 视图框架:Spring MVC 4.0(1)
目录 一.表单标签库 1.1.简介 1.2.常用属性 1.3.form标签与input标签 1.4.checkbox标签 1.5.radiobutton标签 1.6.password标签 1.7.se ...
- 视图框架:Spring MVC 4.0(2)
在<springMVC4(7)模型视图方法源码综合分析>一文中,我们介绍了ModelAndView的用法,它会在控制层方法调用完毕后作为返回值返回,里面封装好了我们的业务逻辑数据和视图对象 ...
随机推荐
- CSS3制作苹果风格键盘
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtMAAAEICAIAAAASh+8XAAAgAElEQVR4nOzdaXBU14E3/FPVBVUq5X
- SNMP 和 NetBios协议理解
一.简单网络管理协议(SNMP,Simple Network Management Protocol)构成了互联网工程工作小组(IETF,Internet Engineering Task For ...
- BestCoder Round #88
传送门:BestCoder Round #88 分析: A题统计字符串中连续字串全为q的个数,预处理以下或加个cnt就好了: 代码: #include <cstdio> #include ...
- 《Java数据结构与算法》笔记-CH4-6优先级队列
/** * 优先级队列 * 效率:插入O(n),删除O(1).第12章介绍如何通过堆来改进insert时间 */ class PriorityQueue { private int maxSize; ...
- nova 配置文件
控制节点 /etc/nova/nova.conf [DEFAULT]cpu_allocation_ratio=32.0service_down_time = 7200#use_local = True ...
- Symbol Table
[Symbol Table] In order for GDB to be useful to us, it needs to be able to refer to variable and fun ...
- Codeforces 660 C. Hard Process (尺取)
题目链接:http://codeforces.com/problemset/problem/660/C 尺取法 #include <bits/stdc++.h> using namespa ...
- [Mac]Mac OS 10.11虚拟机搭建ReactNative遇坑记录
1.命令行安装nvm,一定要加入/.bash_profile,加入以后需要执行source /.bash_profile,使nvm命令行立即生效 2.node一定要安装最新版本,不然执行npm ins ...
- easyui datagrid 的分页刷新按钮
datagrid 刷新bug: 情形: 当用户A,B 同时操作 datagrid时(记录1,记录2.记录3).如果A如果删除记录1, B此时已选中了记录1 ,记录2 , 这时B点击分页中的刷新按 ...
- MVC的System.Web.Mvc.ViewPage小结
Inherits="System.Web.Mvc.ViewPage<dynamic>这一句最好是自己手动修改,如果是维护用户数据,用户对象名是User,改成Inherits=&q ...