博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
springMVC框架建设进程
阅读量:4578 次
发布时间:2019-06-08

本文共 2144 字,大约阅读时间需要 7 分钟。

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文件。

org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath:spring-context.xml
springMVC
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
/WEB-INF/classes/springMVC-context.xml
1
springMVC
*.do

spring-context.xml(这是一个简单的实例,没有涉及到连接数据库等操作,因此该文件不用配置什么东西都能够)

springMVC-context.xml

TestController.java

package com.liuyunlong.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;@Controllerpublic 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+"/";%>        My JSP 'test.jsp' starting page    
Welcome to springMVC

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

转载于:https://www.cnblogs.com/zfyouxi/p/4556083.html

你可能感兴趣的文章
海量数据处理策略
查看>>
hello,world !
查看>>
【Entity Framework】Model First Approach
查看>>
C# DataTable删除行Delete与Remove的问题
查看>>
HDU2586How far away? LCA
查看>>
网络流 - 最大流
查看>>
随手记note(记事簿)
查看>>
JRE System Library 与Java EE Libraries的区别
查看>>
sqlite3性能优化要点
查看>>
颜色分类函数
查看>>
Oracle数据泵详解
查看>>
(中等) HDU 4725 The Shortest Path in Nya Graph,Dijkstra+加点。
查看>>
一个程序员的时间管理
查看>>
sort-归并排序
查看>>
django 快速实现完整登录系统(cookie)
查看>>
.NET中的out和ref关键字
查看>>
Python之ftp服务器
查看>>
KMP预处理
查看>>
AI2(App Inventor 2)离线版服务器(2019.04.28更新)
查看>>
oracle的wm_concat函数实现行转列
查看>>