1.创建一个maven项目
2.在pom.xml 中插入插件
org.apache.tomcat.maven tomcat7-maven-plugin2.2
3.补充web-app文件和web.xml文件
.使用Maven Tomcat插件,要想修改Tomcat的端口和访问路径,可以直接修改pom.xml
org.apache.tomcat.maven tomcat7-maven-plugin2.2 80 /
4.导入servlet依赖
javax.servlet javax.servlet-api3.1.0 provided
5.写一个实现类
package com.study;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
@WebServlet("/demo1")
public class ServletDemo1 implements Servlet {
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
System.out.println("servlet hello world~");
}
public void init(ServletConfig servletConfig) throws ServletException {
}
public ServletConfig getServletConfig() {
return null;
}
public String getServletInfo() {
return null;
}
public void destroy() {
}
}
6.启动Tocat在浏览器输入
http://localhost:8080/web-demo/demo1
控制台打印
servlet hello world~说明程序运行成功



