SpringMVC
该文档主要记录SpringMVC-Maven 搭建及发布到Tomcat7操作流程Round 1: 使用Eclipse创建Maven项目
创建名称SpringMVC-studyDemo的Maven项目
http://i2.运维网.com/images/blog/201808/19/0d724c055907595575aecdfa838b3d7c.png
http://i2.运维网.com/images/blog/201808/19/382a0f637fe0af9cbef217a67c11b5c2.png
http://i2.运维网.com/images/blog/201808/19/1026032cf78cdf9efe7acc4cbdd7be68.png
http://i2.运维网.com/images/blog/201808/19/e5b1fbdc3eaa93d06cb58d5d0dc1e70a.png
http://i2.运维网.com/images/blog/201808/19/75f966d8fa1981c01241dc1891ebbadc.png
其中index.jsp报错,错误信息:Multiple annotations found at this line: - The superclass
http://i2.运维网.com/images/blog/201808/19/86ba7c941c249f8b0d0e298d72a4ec73.png
意思是缺少servlet包,我们可以导入javax.servlet-api-3.1.0.jar包.
只需要在pom.xml中添加依赖即可
javax.servlet
javax.servlet-api
3.1.0
http://i2.运维网.com/images/blog/201808/19/9b88ce527969dd5574b9a8c0eef83236.png
Round 2: 引入Spring MVC
这里主要是在pom.xml中增加对Spring的依赖
5.0.8.RELEASE
org.springframework
spring-core
${spring.version}
org.springframework
spring-web
${spring.version}
org.springframework
spring-webmvc
${spring.version}
Round 3: web.xml 启动支持Spring MVC
这里主要是在web.xml中增加对Spring的启动配置
Archetype Created Web Application
dispatcher
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:springContext.xml
1
dispatcher
/
contextConfigLocation
classpath:springContext.xml
org.springframework.web.context.ContextLoaderListener
Round 4: 配置 springContext.xml
/WEB-INF/views/
.jsp
http://i2.运维网.com/images/blog/201808/19/e19ef25f93258ceff99ceefab107140d.png
Round 5: 创建Spring控制器和视图
Controller 文件
package com.spring.mvc.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class HelloWorldController {
@RequestMapping("/helleworld")
public ModelAndView hellWorld() {
ModelAndView view=new ModelAndView("index.jsp");
return view;
}
}
jsp 文件
Insert title here
this is helloworld jsp
Round 6: 编译项目发布部署
Maven install
http://i2.运维网.com/images/blog/201808/19/e81209bfe78f50b6e2511374d8731edf.png
在\study-demo\target\目录下生成study-demo.war 可直接部署到tomcat/webapp目录下。
http://i2.运维网.com/images/blog/201808/19/96b1ffd86fb0cb681a5a943803ae036d.png
http://i2.运维网.com/images/blog/201808/19/181041edf3cb6988560c988df86ee805.png
Round 7: Q&A
待续.....
页:
[1]