글
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방식으로 접속할때 자동호출");
}
}
'Jsp' 카테고리의 다른 글
자바빈즈를 이용한 계산기 만들기 (0) | 2014.10.29 |
---|---|
Servlet-web.xml로 매핑 (0) | 2014.10.29 |
이클립스에서 servlet-api.jar 인식못할때 해결방법 (1) | 2014.10.24 |
DBCP 이용해서 커넥션 풀 사용하기-JSP방식 (0) | 2014.03.13 |
RECENT COMMENT