1、创建Dynamic Web Project

2、导入spring和springmvc所须要的文件

3、配置web.xml文件

3.1 监听spring上下文容器

3.2 载入spring的xml文件到spring的上下文容器(spring-context.xml)

3.3 配置spring MVC的DispatcherServlet

3.4 载入spring MVC的xml到spring的上下文容器(springMVC-context.xml)

3.5 配置DispatcherServlet所须要拦截的 url(固定了HTTP的格式 如*.do)

4、配置spring的xml文件

主要配置链接数据库等信息

5、配置spring MVC的xml文件

5.1 载入spring的全局配置文件

5.2 扫描指定包下的全部类是注解生效

5.3 配置SpringMVC的视图渲染器

6、写Controller(TestController.java)

7、写jsp文件

运行流程个人总结:接收到请求后会扫描springMVC配置文件里指定的包中的类(controller),依据controller中的注解@RequestMapping("test")找到相应的jsp文件。

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd">
<display-name></display-name> <!--1. 监听spring上下文容器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- 2. 载入spring的xml到spring的上下文容器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-context.xml</param-value>
</context-param> <!-- 3. 配置spring MVC的DispatcherServlet -->
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--4. 载入spring MVC的xml到spring的上下文容器 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/springMVC-context.xml</param-value>
</init-param>
<!-- 启动载入该servlet -->
<load-on-startup>1</load-on-startup>
</servlet> <!--5. 配置DispatcherServlet所须要拦截的 url -->
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping> </web-app>

spring-context.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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<!-- Root Context: defines shared resources visible to all other web components --> </beans>

springMVC-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 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.xsd">
<!-- 载入Spring的全局配置文件 -->
<beans:import resource="spring-context.xml" /> <!-- SpringMVC配置 --> <!-- 通过component-scan 让Spring扫描org.swinglife.controller下的全部的类,让Spring的代码注解生效 -->
<context:component-scan base-package="com.liuyunlong.controller"></context:component-scan> <!-- 配置SpringMVC的视图渲染器, 让其前缀为:/ 后缀为.jsp 将视图渲染到/page/<method返回值>.jsp中 -->
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/page/" p:suffix=".jsp">
</beans:bean> </beans:beans>

TestController.java

package com.liuyunlong.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
public class TestController {
@RequestMapping("test")
public String test(){
return "test";
}
}

jsp文件

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'test.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head> <body>
Welcome to springMVC <br>
</body>
</html>

原文 :http://www.tuicool.com/articles/Nj6Bna

springMVC框架建设进程的更多相关文章

  1. SpringMVC框架搭建 基于注解

    本文将以一个很简单的案例实现 Springmvc框架的基于注解搭建,一下全为个人总结 ,如有错请大家指教!!!!!!!!! 第一步:创建一个动态web工程(在创建时 记得选上自动生成 web.xml ...

  2. 教你搭建SpringMVC框架( 更新中、附源码)

    一.项目目录结构 二.SpringMVC需要使用的jar包 commons-logging-1.2.jar junit-4.10.jar log4j-api-2.0.2.jar log4j-core- ...

  3. springMVC框架访问web-inf下的jsp文件

    博客原文章:http://td.xue163.com/1042/1/10425265.html 用户提出问题:springMVC框架访问web-inf下的jsp文件,具体如下: 使用springMVC ...

  4. SpringMVC框架图解析

    Spring框架提供了构造Web应用程序的全能MVC模块.Spring MVC分离了控制器.模型对象.分派器以及处理程序对象的角色,这种分离让它们更容易进行制定.是一个标准的MVC框架. 那你猜一猜哪 ...

  5. 关于springMVC框架访问web-inf下的jsp文件

    问题:springMVC框架访问web-inf下的jsp文件,具体如下: 使用springMVC,一般都会使用springMVC的视图解析器,大概会这样配置 <property name=&qu ...

  6. springMVC框架下JQuery传递并解析Json数据

    springMVC框架下JQuery传递并解析Json数据

  7. 脚手架快速搭建springMVC框架项目

    apid-framework脚手架快速搭建springMVC框架项目   rapid-framework介绍:   一个类似ruby on rails的java web快速开发脚手架,本着不重复发明轮 ...

  8. springmvc框架下ajax请求传参数中文乱码解决

    springmvc框架下jsp界面通过ajax请求后台数据,传递中文参数到后台显示乱码 解决方法:js代码 运用encodeURI处理两次 /* *掩码处理 */ function maskWord( ...

  9. (文件)图片上传,Spring或SpringMVC框架

    spring或springMVC框架图片(文件)上传 页面部分,用一个简单的form表单提交文件,将图片或文件提交到服务端.一个输入框,用于输入图片的最终名称,一个file文件选择,用于选择图片. 页 ...

随机推荐

  1. 前端构建工具gulp

    前端构建工具gulp使用   前端自动化流程工具,用来合并文件,压缩等. Gulp官网 http://gulpjs.com/ Gulp中文网 http://www.gulpjs.com.cn/ Gul ...

  2. .net 一些常用的工具来破解

    在.net  我们经常提到破 Reflector\SimpleAssemblyExplorer和CFF Explore几个工具. 我们有一个非常简单的Windows Form方案,例如,说他们如何使用 ...

  3. POJ 2538 WERTYU水的问题

    [题目简述]:题意非常easy,没有trick. [分析]:事实上这题还是挺有趣的,在 算法竞赛入门经典中也有这一题. 详见代码: // 120K 0Ms /* 边学边做 -- */ // 字符串:W ...

  4. JS 查找遍历子节点元素

    function nextChildNode(node,clazz,tagName){ var count= node.childElementCount; for(var i=0;i<coun ...

  5. WCF 部署时,soap:address location 显示的是电脑名,而不是ip地址

    部署WCF服务时,发现soap:address location 和wsdl:import location 显示是电脑名,而不是ip地址,这样外面公司的人就无法下载剩下的wsdl,post也会往错误 ...

  6. HDU 1874 畅通公程续 (最短路 水)

    Problem Description 某省自从实行了非常多年的畅通project计划后,最终修建了非常多路.只是路多了也不好,每次要从一个城镇到还有一个城镇时,都有很多种道路方案能够选择,而某些方案 ...

  7. Lua中的weak表——weak table(转)

    弱表(weak table)是一个很有意思的东西,像C++/Java等语言是没有的.弱表的定义是:A weak table is a table whose elements are weak ref ...

  8. MySQL 正則表達式搜索

    products表例如以下: 1. 基本字符匹配 使用正則表達式与LIKE的差别,正則表達式是在整个列搜索,仅仅要prod_name中包括了所搜索的字符就能够了,而LIKE假设不用通配符,那么要求pr ...

  9. NYOJ 14 场地安排

    /* 中国标题的含义: 中国的翻译: 标题效果:寻求预定场地的最大数量,只有一个活动可以安排时间 解决问题的思路:然后使用结构数.之后再构建一个排序,排序结束时间活动.然后基于开始时间为大于一个事件的 ...

  10. 读书时间《JavaScript高级程序设计》一:基础篇

    第一次看了<JavaScript高级程序设计>第二版,那时见到手上的书,第一感觉真是好厚的一本书啊.现在再次回顾一下,看的是<JavaScript高级程序设计>第三版,并记录一 ...