본문 바로가기

개발하자/JSP&Servlet

ServletContext,ServletConfig

Test2.java

==================================

package a.b;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Test2
 */
public class Test2 extends HttpServlet {
 private static final long serialVersionUID = 1L;

    /**
     * Default constructor.
     */
    public Test2() {
        // TODO Auto-generated constructor stub
    }

 /**
  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
 }

 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  response.setContentType("text/html; charset=EUC-KR");
  ServletContext application=this.getServletContext();
  ServletConfig config=this.getServletConfig();
  PrintWriter out=response.getWriter();
  out.println(application.getInitParameter("xxx"));
  out.println(config.getInitParameter("zzz"));
  
 }

}

web.xml

===========================================

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>servlet_0305</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>Test2</display-name>
    <servlet-name>Test2</servlet-name>
    <servlet-class>a.b.Test2</servlet-class>
     <init-param>
          <param-name>
             zzz
          </param-name>
          <param-value>
          yyy
          </param-value>
         </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>Test2</servlet-name>
    <url-pattern>/Test2</url-pattern>
  </servlet-mapping>
    <context-param>
  <param-name>xxx</param-name>
          <param-value>www</param-value>
  </context-param>
</web-app>