java springmvc maven_SpringMVC-Maven 搭建及发布到Tomcat7操作流程

该文档主要记录SpringMVC-Maven 搭建及发布到Tomcat7操作流程

Round 1: 使用Eclipse创建Maven项目

创建名称SpringMVC-studyDemo的Maven项目

b3152091a49a67bfadd373df3b073ab9.png

cfe5cf12db584bdd8ca11a9628e862a7.png

3be92fae08f48bb61a7f68e5bcf570ea.png

92a47ba8d4ddcc199289b44d28b91b69.png

779818e919c70c182dd61eaf185d1741.png

其中index.jsp报错,错误信息:Multiple annotations found at this line: - The superclass

764381f56e2e46e0574796666a3944e5.png

意思是缺少servlet包,我们可以导入javax.servlet-api-3.1.0.jar包.

只需要在pom.xml中添加依赖即可

javax.servlet

javax.servlet-api

3.1.0

36f203e2898fe9e92f9dd172399b6358.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的启动配置

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">

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

xmlns:context="http://www.springframework.org/schema/context"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.0.xsd">

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

/WEB-INF/views/

.jsp

278f110297e9c0b99d4ac2ec192a7f6f.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 文件

pageEncoding="ISO-8859-1"%>

Insert title here

this is helloworld jsp

Round 6: 编译项目发布部署

Maven install

7c7063de6b910973fb07c3d72e7e86e0.png

在\study-demo\target\目录下生成study-demo.war 可直接部署到tomcat/webapp目录下。

0e2fdafc62f31d82918f266b45f9cb22.png

5d0566c532cc8703f364b4da8370affe.png

Round 7: Q&A

待续.....

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值