📄 simpleservlet.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -