application 기본 객체의 초기화 파라미터 관련 기능
*초기화 파라미터 설정법
WEB-INF -> web.xml 문서에서 저장하는것이 초기화 설정법. 그중에 파라미터 설정법이다
1 2 3 4 5 6 7 8 9 | <context-param> <param-name>초기화 파라미터 이름</param-name> <param-value>초기화 파라미터 값</param-value> </context-param> <context-param> <param-name>asdf</param-name> <param-value>asdf</param-value> </context-param> | cs |
*초기화 파라미터 꺼내오는법
1 2 3 4 5 6 7 8 9 | <% Enumeration initParamEnum = application.getInitParameterNames(); while(initParamEnum.hasMoreElements()){ String initParamName = (String)initParamEnum.nextElement(); %> <!-- xml문서에서 저장된 값을 꺼내온다 --> <%=initParamName %> = <%=application.getInitParameter(initParamName) %> | cs |
1.getInitParameter(String name)
:: 이름이 anme인 웹 어플리케이션 초기화 파라미터의 값을 읽어온다. 존재하지않으면 null을 리턴
리턴타입 : String
2.getInitParameterNames()
::웹 어플리케이션 초기화 파라미터의 이름 목록을 리턴한다.
리턴타입 : Enumeration
자원 접근 메서드
1. getRealPath(String Path)
:: 웹어플리케이션 내에서 지정한 경로에 해당하는 자원의 시스템상에서의 자원 경로를 리턴한다.
리턴타입 : String
요약 => 프로젝트명까지의 경로
ex) D:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Front-EndEx
2. getResource(String Path)
:: 웹어플리케이션 내에서 지정한 경로에 해당하는 자원의 시스템상에서의 URL객체를 리턴한다.
3.getResourceAsStream(String Path)
:: 웹 어플리케이션 내에서 지정한 경로에 해당하는 자원으로부터 데이터를 읽어올수있는 InputStrem을 리턴한다
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <% BufferedReader br = null; char[] buff = new char[512]; int len = -1; try { br = new BufferedReader( // 한줄씩 읽어오는 BufferedReader객체 생성 new InputStreamReader( // 2byte씩 읽어올수있는 InputStreamReader 객체 생성 application.getResourceAsStream(resourcePath))); /*어플리케이션 기본객체에서 편리하게 제공하는 ResourceAsStream() 메서드의 리턴타입은 InputStream이기때문에 1byte씩 읽는 메서드이다*/ while ((len = br.read(buff)) != -1) { out.print(new String(buff, 0, len)); } } catch (IOException ioe) { out.println("익셉션 발생 : " + ioe.getMessage()); } finally { if (br != null) try { br.close(); } catch (IOException ioe) { } } %> | cs |
'JAVA > Spring MVC1패턴' 카테고리의 다른 글
JSP - Cookie(쿠키) (0) | 2018.07.16 |
---|---|
JSP - error 페이지 지정/초기화지정 (0) | 2018.07.16 |
JSP - <jsp:forward>액션 태그 (0) | 2018.07.16 |
JSP - include/param 액션태그 (0) | 2018.07.13 |
JSP - 기본객체와 영역의 개념 (0) | 2018.07.13 |