📄 helloservlet.java
字号:
import javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.util.*;/** * This servlet demonstrates how to service HTTP GET requests. It also prints any URL * parameters from the query string. */public class HelloServlet extends HttpServlet { /** * Process the HTTP Get request. The other HTTP request types will be handled * by the default handlers defined by HttpServlet. */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); // Start the HTML document out.println("<html>"); // Set the title of the document out.println("<head><title>HelloServlet</title></head>"); // Start the document body out.println("<body>"); out.println("<p>HelloServlet received a GET request. The parameters follow.</p>"); /** * Now loop through all of the URL parameters printing their * names and values. This assumes that each parameter has * only one value. If there could be more than one value per * parameter, it could use request.getParameterValues rather * than request.getParameter. */ Enumeration params = request.getParameterNames(); while (params.hasMoreElements()) { String param = (String)params.nextElement(); out.println("<p>"); out.println(param + "=" + request.getParameter(param)); out.println("</p>"); } out.println("</body></html>"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -