1 6 7 package web; 8 9 import java.io.*; 10 import java.net.*; 11 12 import javax.servlet.*; 13 import javax.servlet.http.*; 14 15 20 public class Test extends HttpServlet { 21 22 26 protected void processRequest(HttpServletRequest request, HttpServletResponse response) 27 throws ServletException, IOException { 28 response.setContentType("text/html;charset=UTF-8"); 29 PrintWriter out = response.getWriter(); 30 31 out.println("<html>"); 32 out.println("<head>"); 33 out.println("<title>Servlet Test</title>"); 34 out.println("</head>"); 35 out.println("<body>"); 36 out.println("<h1>Servlet Test at " + request.getContextPath () + "</h1>"); 37 out.println("</body>"); 38 out.println("</html>"); 39 40 out.close(); 41 } 42 43 48 protected void doGet(HttpServletRequest request, HttpServletResponse response) 49 throws ServletException, IOException { 50 processRequest(request, response); 51 } 52 53 57 protected void doPost(HttpServletRequest request, HttpServletResponse response) 58 throws ServletException, IOException { 59 processRequest(request, response); 60 } 61 62 64 public String getServletInfo() { 65 return "Short description"; 66 } 67 } 69 | Popular Tags |