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. Test SRM Level Two: CountExpressions, Brute Force

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=8157 这道题目跟扑克牌算24的题目比较像,但要简单一些.点击查 ...

  2. SharePoint 2010 BCS - 概要

    博客地址 http://blog.csdn.net/foxdave SharePoint 2010首次引入了BCS的概念 - Business Connectivity Service.即业务连接服务 ...

  3. MVC @Html控件

    传统的Html元素不能和服务端数据进行绑定 HtmlHelper类提供了一系列的方法来生成Html元素 并可以实现与数据绑定在一起 然后生成Html Html.BeginForm(actionName ...

  4. 中文/英文双语言版本TWRP for Nexus5 -hammerheadcaf

    编译及作者:laser杨万荣 编译时间: 2015-05-17 编译目的:用于刷cm-12.0 和cm-12.1 ROM 因为现在Nexus5 最新的 CM是 hammerheadcaf ,即和 ao ...

  5. mapreduce程序来实现分类

    文件的内容例如以下所看到的: 5 45 8 876 6 45 要求最后的输出格式: 1    5 2    6 3    8 4    45 5    45 5    876 首先,这个题目是须要对文 ...

  6. sql基础之DDL(Data Definition Languages)

    好久没写SQL语句了,复习一下. DDL数据定义语言,DDL定义了不同的数据段.数据库.表.列.索引等数据库对象的定义.经常使用的DDL语句包含create.drop.alter等等. 登录数据:my ...

  7. java提高篇(六)-----关键字static

    一. static代表着什么 在Java中并不存在全局变量的概念,但是我们可以通过static来实现一个"伪全局"的概念,在Java中static表示"全局"或 ...

  8. 开源Math.NET基础数学类库使用(07)一些常用的数学物理常数

    原文:[原创]开源Math.NET基础数学类库使用(07)一些常用的数学物理常数               本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/ ...

  9. iPhone发展【一】从HelloWorld开始

    转载请注明出处.原文网址:http://blog.csdn.net/m_changgong/article/details/8013553 作者:张燕广 从经典的HelloWorld開始踏入iPhon ...

  10. 【Cocos2d-x】Mac 在 Cocos2d-x 3.X 打包Android

    今天cocos2d-x 3.0正式版最终公布了,下午特地下载了来尝尝鲜,废话不多说了. 3.0正式版的环境搭建和之前的RC版事实上是一样的,太多的教程也写了怎样搭建.今天来写写我自己是怎样来搭建的. ...