准备条件
- eclipse
- jdk1.8 (配置jdk环境)
- apache-tomcat-8.5.97(记住安装位置)
一
点击完成
开始创建javaweb项目
import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;public class test extends HttpServlet {@Overrideprotected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// 获取 PrintWriter 对象response.setCharacterEncoding("UTF-8");response.setContentType("text/plain; charset=UTF-8");PrintWriter pw = response.getWriter();// 输出 Hello Worldpw.print("输出 Hello World");}
}
目录结构如下:
<?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>
<servlet-name>fly</servlet-name>
<servlet-class>fly.test</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>fly</servlet-name>
<url-pattern>/hi</url-pattern>
</servlet-mapping>
</web-app>
会出现此界面表示成功