import java.io.*;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class HelloTest
 */
@WebServlet("/HelloTest")
public class HelloTest extends HttpServlet {
 
 public void init(ServletConfig config) throws ServletException {
  // TODO Auto-generated method stub
  System.out.println("맨처음 사이트 접속시 호출되는 메서드");
  System.out.println("생성자와 기능이같다");
 }

 /**
  * @see Servlet#destroy()
  */
 public void destroy() {
  // TODO Auto-generated method stub
  System.out.println("웹어플리케이션이 종료될때 자동호출");
 }

 /**
  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  System.out.println("사용자가 get방식으로 접속할떄 자동호출");
  response.setContentType("text/html;charset=euc-kr");

  //출력객체
  PrintWriter out=response.getWriter();
  out.println("<html>");
  out.println("<body>");
  out.println("<h2>구구단 출력</h2>");
  out.println("<table border=1>");
   for(int i=2;i<=9;i++){
    out.println("<tr>");
     for(int j=1;j<10;j++){
      out.println("<td>");
      out.println(""+i+"*"+j+"="+(i*j));
      out.println("</td>");
     }
     out.println("</tr>");
   }
   out.println("</table>");
   out.println("</body>");
   out.println("</html>");
 }

 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  System.out.println("사용자가 post방식으로 접속할때 자동호출");
 }

}

 

 


by 맑은소금 2014. 10. 24. 02:24