1.创建项目
File->Project->JAVA Eenterprise
勾选Web Application,其它框架按自己需求勾选
然后Next,选择工程路径, 点击Finish。
2.配置Tomcat
配置项目访问根路径
3.配置部署路径
4.创建一个测试接口
1.在src目录下创建ServletTest
@WebServlet(name = "ServletTest")
public class ServletTest extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter writer = response.getWriter();
writer.write("Hello");
writer.close();
}
}
2.配置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_3_1.xsd"
version="3.1">
<servlet-mapping>
<servlet-name>ServletTest</servlet-name>
<url-pattern>/ServletTest</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>ServletTest</servlet-name>
<servlet-class>com.gamepp.ServletTest</servlet-class>
</servlet>
</web-app>
3.启动tomcat
访问 http://localhost:8080/Gamepp/ServletTest
成功返回 “Hello”