출처 : http://micropilot.tistory.com/1071
모든 JSP에서 사용할 수 있도록 init-param을 설정하는 예
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>SAVE_ROOT</param-name>
<param-value>e:/StMgt</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
서블릿과 JSP에 초기화 파라미터를 설정하는 다른 예들
<web-app> <!-- Init parameters for the servlet ReadInitParams --> |
위에서 선언한 JSP url-pattern 도 반드시 필요함.
-
Reading the Init Parameters from the web.xml file
The
ServletConfig
object provides a handle to the initialization parameters defined inweb.xml
.ServletConfig
's method:getInitParameter()
is used to retrieve the init parameters. The following code snippet illustrates how to read the init parameters from theinit()
and theservice()
methods of a servlet.
- <b></b>
public void init(ServletConfig config) throws ServletException { String emailHost = config.getInitParameter("emailHost"); String webMaster = config.getInitParameter("webMaster");}
or public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String host = getServletConfig().getInitParameter("emailHost");
String master = getServletConfig().getInitParameter("webMaster");}
To retrieve all the init parameters, use
Enumeration
and ServletConfig
's getInitParmeterNames()
. For example,public void init(ServletConfig config) throws ServletException { Enumeration params = config.getInitParameterNames(); // Print the init parameter names and values to the console while (params.hasMoreElements()) { String name = (String) params.nextElement(); System.out.println("Parameter Name: " + name + " Value: " + config.getInitParameter(name)); }} |
Reading the init parameters from the web.xml file in a JSP
The implicit object - ServletConfig
can be read either in the jspInit()
method or directly to retrieve the values of init parameters. Following is the code snippet to retrieve the values from readInitParamJSP.jsp
<%@ page language="java"%> |
'JSP' 카테고리의 다른 글
[jquery] 멀티 파일 업로드 (2) | 2014.03.25 |
---|---|
파일 확장자에 따라 아이콘이 달라지는 소스 구현 (0) | 2014.03.25 |
JSP에서 엑셀(excel) 파일 DB에 저장하기 (1) | 2014.03.25 |
[JSTL] varStatus 사용하기.. (JSTL 루프 상태값을 반환해준다) (0) | 2014.03.25 |
[링크스크랩] JSP 자료실 게시판 업로드와 다운로드 폼 (0) | 2014.03.25 |
elements이용한 다중파얼업로드 (갯수제한 및 삭제, 글자수 제한까지 한번에) (0) | 2014.03.25 |
ajax를 이용한 동적인 파일 업로드 (0) | 2014.03.25 |
EL Tag 라이브러리 사용하기 ${requestScope} (0) | 2014.03.25 |