一、点击 “Create New Project”
截屏2019-11-19上午9.01.59.png二、选中java Enterprise 并勾选 Web Application(4.0)
截屏2019-11-19上午9.04.49.png三、设置项目名称后点击 “Finish”
截屏2019-11-19上午9.07.15.png四、项目目录结构如下
截屏2019-11-19上午9.08.28.png五、配置Tomcat服务器 并点击图中三角形图标运行
截屏2019-11-19上午9.11.22.png六、创建servlet
截屏2019-11-19上午9.22.46.png 截屏2019-11-19上午9.23.33.png 截屏2019-11-19上午9.24.23.png 截屏2019-11-19上午9.25.36.pngpackage com.mycompany;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet(name = "test")
public class test extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Hello World!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello World!</h1>");
out.println("</body>");
out.println("</html>");
}
}
截屏2019-11-19上午9.53.19.png
运行看效果
截屏2019-11-19上午9.54.33.png
网友评论