2010. 7. 5. 20:38 JAVA , JSP
서블릿 파일 생성하고 실행
package review;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class LifeCycleServlet
*/
public class LifeCycleServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
int count;
/**
* @see HttpServlet#HttpServlet()
*/
public LifeCycleServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see Servlet#init(ServletConfig)
*/
public void init(ServletConfig config) throws ServletException {
// TODO Auto-generated method stub
super.init(config);
System.out.println("init() called");
count = 0;
}
/**
* @see Servlet#destroy()
*/
public void destroy() {
// TODO Auto-generated method stub
System.out.println("destroy() called ");
count = 0;
}
/**
* @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
*/
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html;charset=euc-kr");
PrintWriter out = response.getWriter();
out.println(++count);
}
}
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%!
int count ;
public void jspInit() {
count = 0;
System.out.println("jspInit() called : " + count);
}
public void jspDetroy() {
System.out.println("jspDestroy() called : " + count);
count = 0;
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
count = <%=++count %>
</body>
</html>
'JAVA , JSP' 카테고리의 다른 글
redirect (0) | 2010.07.05 |
---|---|
include directive vs include action tag (0) | 2010.07.05 |
[게시판] web 개발환경 설정, DB 설정, web.xml (0) | 2010.07.03 |
우분투에서 서버에 접속하는 방법 및 vi editor 명령어 (0) | 2010.07.03 |
엑셀 파일 읽어와서 화면에 출력하는 소스 (0) | 2009.10.16 |