springMVC框架建设进程
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框架建设进程的更多相关文章
- SpringMVC框架搭建 基于注解
本文将以一个很简单的案例实现 Springmvc框架的基于注解搭建,一下全为个人总结 ,如有错请大家指教!!!!!!!!! 第一步:创建一个动态web工程(在创建时 记得选上自动生成 web.xml ...
- 教你搭建SpringMVC框架( 更新中、附源码)
一.项目目录结构 二.SpringMVC需要使用的jar包 commons-logging-1.2.jar junit-4.10.jar log4j-api-2.0.2.jar log4j-core- ...
- springMVC框架访问web-inf下的jsp文件
博客原文章:http://td.xue163.com/1042/1/10425265.html 用户提出问题:springMVC框架访问web-inf下的jsp文件,具体如下: 使用springMVC ...
- SpringMVC框架图解析
Spring框架提供了构造Web应用程序的全能MVC模块.Spring MVC分离了控制器.模型对象.分派器以及处理程序对象的角色,这种分离让它们更容易进行制定.是一个标准的MVC框架. 那你猜一猜哪 ...
- 关于springMVC框架访问web-inf下的jsp文件
问题:springMVC框架访问web-inf下的jsp文件,具体如下: 使用springMVC,一般都会使用springMVC的视图解析器,大概会这样配置 <property name=&qu ...
- springMVC框架下JQuery传递并解析Json数据
springMVC框架下JQuery传递并解析Json数据
- 脚手架快速搭建springMVC框架项目
apid-framework脚手架快速搭建springMVC框架项目 rapid-framework介绍: 一个类似ruby on rails的java web快速开发脚手架,本着不重复发明轮 ...
- springmvc框架下ajax请求传参数中文乱码解决
springmvc框架下jsp界面通过ajax请求后台数据,传递中文参数到后台显示乱码 解决方法:js代码 运用encodeURI处理两次 /* *掩码处理 */ function maskWord( ...
- (文件)图片上传,Spring或SpringMVC框架
spring或springMVC框架图片(文件)上传 页面部分,用一个简单的form表单提交文件,将图片或文件提交到服务端.一个输入框,用于输入图片的最终名称,一个file文件选择,用于选择图片. 页 ...
随机推荐
- 怎么样Eclipse IDE for C/C++ Developers正确编译GTK规划?(解决)
<span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 25.99 ...
- ImportError with IronPython in C#
I was using IronPython to execute python code inside my C# implementation lately, and I encountered ...
- JSP-简单的练习省略显示长字符串
<%@ page contentType="text/html; charset=gb2312" %> <!-- JSP指令标签 --> <%@ pa ...
- CentOS 6.3 安装 samba 共享(转)
PHP环境在linux下,但是开发的时候用的是windows,于是我用了samba将linux的一个目录共享,然后在windows上做映射,这样就可以直接在windows下编辑linux上的文件了 首 ...
- 深入浅出JMS(一)——JMS简要
假设手机只能实时通话.没有邮件和短信功能发生?一个电话回来.只是没有足够的时间去连接.然后传递这款手机的信息肯定是不接受. 么不能先将信息存下来.当用户须要查看信息的时候再去获得信息呢?伴随着这个疑惑 ...
- Android - 和其他APP交互 - 获得activity的返回值
启用另一个activity不一定是单向的.也可以启用另一个activity并且获得返回值.要获得返回值的话,调用startActivityForResult()(而不是startActivity()) ...
- C# WebBrowser.DocumentCompleted 多次调用解决方法
大概出现了以下几种情况. 1.WebBrowser载入一个页面后DocumentCompleted事件会执行两次,但这两次的ReadyState状态不一样,分别是Intercative和Complet ...
- 【Android基础】短信的发送
//Button的点击事件 @Override public void onClick(View v) { // 接受者电话号码 Uri uri = Uri.parse("smsto:123 ...
- SVM算法实现(一)
关键字(keywords):SVM 支持向量机 SMO算法 实现 机器学习 假设对SVM原理不是非常懂的,能够先看一下入门的视频,对帮助理解非常实用的,然后再深入一点能够看看这几篇入门文章,作者写得挺 ...
- think in coding
,想想除了技术还有什么? 你假设形而下的去纠结技术.仅仅会变成技术的傀儡.他们仅仅是一种表达的方式? 希望你能够形而上的去看待技术,技术千变万化,但都是为了解决这个问题的方式. 请问问自己,自己问题是 ...