java springmvc maven_使用Maven创建的springmvc工程发布到tomcat

使用Maven创建的springmvc工程发布到tomcat

1、建好tomcat环境:(点击add, 选择Tomcat)

(如果列表中没有Apache Tomcat,可能是因为eclipse缺少插件,可以:

Help > Install New Software

Select the neon site: http://download.eclipse.org/releases/neon

Expand the 'Web, XML, and Java EE Development' node

Select and install 'JST Server Adapters' and 'JST Server Adapters Extensions'

Window > Preferences > Server > Runtime Environments > Add)

2f3cccbe83f30751630995fc88dc2efc.png

默认会同时新建一个tomcat server

2、创建一个Maven Project, 选择类型为webapp

d5685864fd06a640d74b54fb1eb2589a.png

15ae93d9539761d3952c2cb9174ffa5c.png

32a912d4c2f9f0708d6218e64febe9d7.png

3、双击pom.xml, 添加依赖

077a89fded1d506205cd639296cfcb9d.png

4、修改maven project的properties中的project Facets

06a7bbca4afcf3e2993fe18a386f5a43.png

勾上Dynamic Web Module

49b76c2a079d5ddad016efb735b4e357.png

点击futher configuration available...   修改Content directory为:src/main/webapp

3ddb0224314629f590439a98fa805da9.png

选择工程的properties,找到Deployment Assembly, 可以看到

775559a7338c30d7443231060ade3c9b.png

再点击Add,选择Java Build Path Entries,将Maven的包添加到运行时。(否则可能在Eclipse调试时,加时过程中找不到org.springframework.web.servlet.DispatcherServlet)

858982cce9af0eaa28ce5753f0eaabee.png

08b76dbb5b40c5f64c0a8146297a3286.png

36a3e9cb28672535ccf4b62ff34f942e.png

5、修改web.xml

xmlns="http://java.sun.com/xml/ns/j2ee"

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

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

Spring MVC Application

HelloWeb

org.springframework.web.servlet.DispatcherServlet

1

HelloWeb

/

6、WEB-INF下加入HelloWeb-servlent.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">

7、在src/main/java下新建com.tutorialspoint.HelloController

package com.tutorialspoint;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.ui.ModelMap;

@Controller

@RequestMapping("/hello")

public class HelloController{

@RequestMapping(method = RequestMethod.GET)

public String printHello(ModelMap model) {

model.addAttribute("message", "Hello Spring MVC Framework!");

return "hello";

}

}

8、在WEB-INF下新建jsp目录,放入hello.jsp

Hello World

${message}

、右击右下脚的Tomcat Server, 选择Add and Remove

2161cc530418c2629aa5319373b06952.png

将工程添加到server

556f380d1c7d7e44297406f0ba25e4c1.png

4、run on server

bf50645c0123f1ffc4da5ffe19a7f700.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值