구 분 | 적용 | 범위 설정 |
ServletConfig |
| <servlet> <servlet-name> </servlet-name> <servlet-class> </servlet-class> <init-param> <param-name> </param-name> <param-value> </param-value> </init-param> </servlet> |
ServletContext | 동일 웹 애플리케이션 내 모든 서블릿(또는 JSP)에서 사용 할 수 있다. | <context-param> <param-name> </param-name> <param-value> </param-value> </context-param> |
● 예제
test com.test1.TestServlet name han age 20 test /test city seoul
protected void process(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { ServletConfig config = getServletConfig(); //해당 서블릿에서만 사용가능 ServletContext context = getServletContext(); //동일한 웹어플리케이션 어디서든 접근가능 String name = config.getInitParameter("name"); String age = config.getInitParameter("age"); String city = context.getInitParameter("city"); //로그설정 context.log("로그를 출력합니드아"); resp.setContentType("text/html;charset=utf-8"); PrintWriter out = resp.getWriter(); out.print("name:" + name + "
"); out.print("age:" + age + "
"); out.print("city:" + city + "
"); }
'JSP > JspServlet' 카테고리의 다른 글
XML 기본구조 (0) | 2013.08.16 |
---|---|
Tomcat web.xml (0) | 2013.08.16 |
자바클래스 메서드에 접근 (0) | 2013.08.16 |
서블릿에서 out.print() (0) | 2013.08.16 |
tag : core (0) | 2013.08.16 |