IDEA创建Servlet项目(5)

6、创建Servlet测试

在src下新建一个测试用的Servlet,如下图:


IDEA创建Servlet项目(5)


重写获取get/post访问的函数


IDEA创建Servlet项目(5)


IDEA创建Servlet项目(5)


package com.item.test;
 
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;
@WebServlet({"/Action"})
public class Action extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("执行过doGet");
        doPost(req,resp);
    }
 
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("执行过doPost");
        resp.getWriter().write("<h1>Hello World</h1>");
    }
}
上一篇:《Power Designer系统分析与建模实战》——1.1 软件建模


下一篇:DM达梦数据库 - 设置忽略关键字方法,login关键字处理实例演示