simpleservlet.java
来自「JSP课件以及一个网上书店系统程序,带数据库」· Java 代码 · 共 38 行
JAVA
38 行
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class SimpleServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=gb2312";
//Initialize global variables
public void init() throws ServletException {
}
public void init(ServletConfig config) throws javax.servlet.ServletException {
super.init();
}
public void destroy() {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter print=response.getWriter();
print.println("<HTML>");
print.println("<head><title>Get请求</title></head>");
print.println("<body>");
print.println("<h2>Servlet接收到客户端的Get请求</h2>");
print.println("</bod></html>");
print.close();
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter print=response.getWriter();
print.println("<HTML>");
print.println("<head><title>Post请求</title></head>");
print.println("<body>");
print.println("<h2>Servlet接收到客户端的Post请求</h2>");
print.println("</bod></html>");
print.close();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?