servlet파일 작성(1) - GenericServlet 클래스를 이용
자바 기본 클래스를 Servlet으로 구성하기 위해
GenericServlet 을 상속받는 클래스로 설계
public class Test004 extends GenericServlet { private static final long serialVersionUID = 1L; @Override public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { response.setContentType("text/html; charset=UTF-8"); try { PrintWriter out = response.getWriter(); out.print("<html>"); out.print("<head>"); out.print("<title>"); out.print("Test004.java"); out.print("</title>"); out.print("</head>"); out.print("<body>"); out.print("<div>"); out.print("<h1>"); out.print("서블릿 관련 실습"); out.print("</h1>"); out.print("<hr>"); out.print("</div>"); out.print("<div>"); out.print("<h2>"); out.print("GenericServlet 클래스를 이용한 서블릿 테스트"); out.print("</h2>"); out.print("</div>"); out.print("</body>"); out.print("</html>"); } catch (Exception e) { System.out.println(e.toString()); } } }
servlet파일 작성(1-2)
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.print("<html>"); out.print("<head>"); out.print("</head>"); out.print("<body>"); out.print("hello"); out.print("</html>");