1.首先要在windows中安装tomcat和maven;如果没有可以去看我之前的博客
2.创建好maven项目之后,在pom.xml文件中加入这一行
3.鼠标右键项目打开"Open Module Settings"
4.点击Moudle下的web,双击飘红的地方
5.复制其路径然后点击确定
6.点击"+"号,选择"web.xml"
用刚才复制的地址替换"\WEB-INF\web.xml"以前的地址
替换完之后,点击"ok"
出现如下界面
在Artifacts目录下有对应的war文件,最后点击"ok"即可
7.为了测试把login.html放在webapp文件夹下(login.html是自己写的,仅仅为了测试,没有什么其他的含义)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>用户登录</title>
</head>
<body>
<h3>登录页面</h3>
<form method="post" action="login">
用户名:<input type="text" name="username" />
<br><!-- br代表换行符 -->
密码:<input type="password" name="password" />
<input type="submit" value="登录" />
</form>
</body>
</html>
8.鼠标点击"maven",进入之后自己的Plugins可能飘红,表示插件没有下载到本次仓库,等待IDEA下载好就不会飘红了。如果自己不想下载,可以用我网盘上存的仓库
M2Repository提取码:s9x7
等不漂红了双击"package"
可以看到打包成功,并且新生成了target目录其下面有关于该项目的war包
9.鼠标右击war包,找到war包位置
复制war包
把这个war包复制到自己解压的tomcat根路径的webapps下
按 win + R键,输入cmd进入,然后输入startup启动Tomcat
这时候tomcat根路径的webapps下会自动解压那个war包
10.双击自动解压的文件夹,即可看到login.html文件
打开谷歌浏览器将login.html的路径写进去,访问出现登录页面即可说明成功