intellij IDEA 创建javaweb项目
1,new一个maven项目
2,maven项目创建完成后,在main目录下new一个webapp目录,pom.xml中添加要打包的方式,然后点击软件界面右侧的选项栏中的Maven,在弹出的页面中点击刷新
3,设置Maven
4,依赖servlet
5,使用servldet
web.xml中做servlet的映射
##常用命令
mvn clean //清理之前生成的东西
mvn package //打包
6.配置tomcatServer
之后点击apply-->ok 在maven选项中shua刷新整个项目
7,运行
运行成功,会弹出一个网页,显示的内容是index.jsp中配置的title和hello maven
常用配置
POM.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.eyesee</groupId>
<artifactId>hello-maven</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<!--HelloServlet类-->
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>com.example.hello.maven.servlet.HelloServlet</servlet-class>
</servlet>
<!--映射到HelloServlet下的/servlet/hello目录-->
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/servlet/hello</url-pattern>
</servlet-mapping>
</web-app>
index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
hello maven
</body>
</html>