e1035. the quintessential servlet.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 34 行

TXT
34
字号
This example implements a servlet that handles GET requests. 
    package com.mycompany;
    
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    
    public class MyServlet extends HttpServlet {
        // This method is called by the servlet container just before this servlet
        // is put into service. Note that it is possible that more than one
        // instance of this servlet can be created in the same VM.
        public void init() throws ServletException {
            // Initialization code...
            // See e1036 Getting and Setting Initialization Parameters for a Servlet
        }
    
        // This method is called by the servlet container to process a GET request.
        // There may be many threads calling this method simultaneously.
        public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
            PrintWriter out = resp.getWriter();
            out.println("<html><head><title>A Simple Servlet</title></head><body>");
            out.println("Today is "+(new java.util.Date()));
            out.println("</body></html>");
            out.close();
        }
    
        // This method is called by the servlet container just after this servlet
        // is removed from service.
        public void destroy() {
            // Shutdown code...
        }
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?