Web.xml 구성
web.xml에 설정된 초기화 파라미터 읽기
String filename = getInitParameter("FILE_NAME");
ServletConfig config = getServletConfig();
String filename = config.getInitParameter("FILE_NAME");
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<servlet>
<servlet-name>fibonacci-servlet</servlet-name>
<servlet-class>FibonacciServlet</servlet-class>
<load-on-startup>0</load-on-startup> --
</servlet>
<servlet-mapping>
<servlet-name>fibonacci-servlet</servlet-name>
<url-pattern>/fibonacci</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>greeting-servlet</servlet-name>
<servlet-class>GreetingServlet</servlet-class>
<init-param> --서블릿 초기화 파리미터
<param-name>FILE_NAME</param-name>
<param-value>C:\\data\\greeting_log.txt</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>greeting-servlet</servlet-name>
<url-pattern>/greeting</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>dbname-jsp</servlet-name>
<jsp-file>/DBName.jsp</jsp-file> --JSP파일 연결할 때 파일 명 앞에 '/'은 들어가야됨.
<init-param>
<param-name>DB_NAME</param-name>
<param-value>malldb</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dbname-jsp</servlet-name>
<url-pattern>/dbname</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>server-info-servlet</servlet-name>
<servlet-class>ServerInfoServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>server-info-servlet</servlet-name>
<url-pattern>/server-info</url-pattern>
</servlet-mapping>
<context-param> --웹전체에서 사용할 때
<param-name>DB_NAME</param-name> --application.getInitParameter("DB_NAME");
<param-value>bankdb</param-value>
</context-param>
</web-app>
'JavaWeb' 카테고리의 다른 글
[Spring] spring framework 설치 (0) | 2015.09.07 |
---|---|
[JSP] 익스프레션 (0) | 2015.09.07 |
[JSP] 서블릿 클래스의 init, destory 메서드 (0) | 2015.09.07 |
[JSP]useBean (0) | 2015.09.07 |
[JSP] include (0) | 2015.09.07 |
댓글