springmvc项目部署服务器,springMvc 环境搭建 - tomcat 热部署到服务器

1、使用spring framework 5.2.1 REALSE

75afd2d2abbc0f36dd4397704fed5eea.png

2、创建maven 工程

5a98509e3b61a4853721f2dcbeb90969.png

bc31d07d16edd255fbf3ea02bc0b9cce.png

d88e4202580a350201f71046d7ed82ac.png

点击完成,这个maven工程就是搭建OK了。

---- 本地安装tomcat,我使用的版本是tomcat8.5

ad69932eab90cf67e387355773ff9ba8.png

c1556a791e26727753893400eb00bbde.png

添加后,会出现这个。

23a6f21b5a20b61e048f3aa4467c4e5f.png

引入springMVC,pom.xml

org.springframework

spring-webmvc

5.2.1.RELEASE

---需要配置的目录如下:

218ad23d67f379888da17453d601436d.png

web.xml 是默认的文件在里面配置如下:

/p>

"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

"http://java.sun.com/dtd/web-app_2_3.dtd" >

Archetype Created Web Application

springmvc

org.springframework.web.servlet.DispatcherServlet

1

springmvc

/

servlet 的 name 是 springmvc 要和上面截图的springmvc-servlet.xml 前缀一样,不然在启动时会遇到读取不到的问题。

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

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

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

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/mvc

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

/WEB-INF/jsp/

.jsp

设定component-scan 扫描包的,

16cb8f80658a55a8777587ed2f365ea9.png

---HelloController

package com.fandong.weapon.controller;

import org.springframework.stereotype.Controller;

import org.springframework.ui.ModelMap;

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

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

@Controller

public class HelloController {

@RequestMapping(value="/hello",method=RequestMethod.GET)

public String printHello(ModelMap model) {

model.addAttribute("message","你好的,小子");

System.out.println("-------------------------************** hmemee");

return "hello";

}

}

设定jsp页面:

f9778b7111770f50fda6d6daa84d9f00.png

这个表,

pageEncoding="UTF-8"%>

Insert title here

${message}

注意 isELIgnored="false" 否则到时message 会无法序列化。

----本地启动。

---搭建tomcat 服务器。

下载tomcat8.5  解压:

启动:

cd /tomcat/bin

./startup.sh

---修改tomcat文件:

[root@hadoop01 conf]# ls

Catalina catalina.policy catalina.properties context.xml jaspic-providers.xml jaspic-providers.xsd logging.properties server.xml tomcat-users.xml tomcat-users.xsd web.xml

[root@hadoop01 conf]# cat tomcat-users.xml

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

xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"

version="1.0">

[root@hadoop01 conf]#

设定用户、账户和密码。

--在修改可以远程访问:

[root@hadoop01 manager]# pwd

/opt/tomcat/tomcat-8.5.50/webapps/manager

[root@hadoop01 manager]# cd META-INF/

[root@hadoop01 META-INF]# ls

context.xml

[root@hadoop01 META-INF]# cat context.xml

[root@hadoop01 META-INF]#

注释掉: 

----在pom.xml 配置tomcat-maven 插件

org.apache.tomcat.maven

tomcat7-maven-plugin

2.2

/

http://hadoop01.fandong.com:8080/manager/text

tomcat

tomcat

true

这里一定是true 不然更新会出错的。

5ec49760aef4d2b5fb0ad19fce3af27b.png

--结果:

472e00d232b126bf52e04821d6023290.png

---浏览器访问:

890a6f1f87e8d0ac0d791a3bbea56635.png