webapp > WEB-INT > lib > web.xml >>
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>chap05.servlet.HelloServlet</servlet-class>
</servlet>
webapp > WEB-INT > lib > web.xml >>
<servlet>
<servlet-name>myservlet2</servlet-name>
<jsp-file>/encoding.jsp</jsp-file>
</servlet>
webapp > WEB-INT > lib > web.xml >>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>myservlet2</servlet-name>
<url-pattern>/encoding_test</url-pattern>
</servlet-mapping>
<!-- ์๋ฌด๋ฐ ๋งคํ์๋ ๊ฑธ๋ฆฌ์ง ์์ ์์ฒญ์ elseServlet์ผ๋ก ์ด๋ํด! -->
<servlet>
<servlet-name>elseServlet</servlet-name>
<servlet-class>chap05.servlet.ElseServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>elseServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
webapp > WEB-INT > lib > web.xml >>
<context-param>
<param-name>account_id</param-name>
<param-value>hr</param-value>
</context-param>
<context-param>
<param-name>account_pw</param-name>
<param-value>1234</param-value>
</context-param>
ElseServlet.java (์๋ธ๋ฆฟ) ์์ ์ ๊ทผํ๊ธฐ >>
public class ElseServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// JSP application scope์ ์๋ธ๋ฆฟ ๋ฒ์
ServletContext application = request.getServletContext();
// web.xml์์ ๋ฑ๋กํ context-param์ application scope์ ๋ค์ด์๋ค
System.out.println(application.getInitParameter("account_id"));
System.out.println(application.getInitParameter("account_pw"));
// JSP session scope์ ์๋ธ๋ฆฟ ๋ฒ์
HttpSession session = request.getSession();
response.getWriter()
.append("<html><head><title></title></head>")
.append("<body>404 Not Found</body>");
}
}
๐บ ์ถ๋ ฅ ๊ฒฐ๊ณผ >>
ElseServlet.java (์๋ธ๋ฆฟ) >>
public class ElseServlet extends HttpServlet {
Color mainColor;
@Override
public void init(ServletConfig config) throws ServletException {
System.out.println(config.getInitParameter("main_color"));
System.out.println(config.getInitParameter("logo_path"));
}
response.getWriter()
.append("<html><head><title></title></head>")
.append("<body>404 Not Found</body>");
}
}
๐บ ์ถ๋ ฅ ๊ฒฐ๊ณผ >>