Technology/Programming
JSTL / 웹페이지 경로 알아내기 (상대경로, 절대경로)
Yonglae Cho
2009. 10. 28. 11:21
JAVA와 JSTL로 절대경로, 상대경로, 웹페이지 경로를 알아내기
서버정보
Server Info : <%= application.getServerInfo()%>
상대 디렉토리경로
Context Path :
${pageContext.request.contextPath} or <%= request.getContextPath() %>
페이지가 속해있는 파일경로
URL Path : <%= request.getRequestURI()%>
절대경로
Real App Path(Absolute Path) : <%= application.getRealPath("/") %>
예제)
절대경로
String path = application.getRealPath("/");
out.println(path); // 현재 파일이 위치한 경로 (예: /home/test)
String uploadPath = request.getRealPath("file");
out.println(uploadPath); // 현재 파일이 위치한 경로에 /file 디렉토리가 더해진다. (예ㅣ /home/test/file)
또 다른 절대경로 얻는 법
String saveDir = "/file/";
ServletContext context = getServletContext();
realFolder = context.getRealPath(saveDir);
String path = application.getRealPath("/");
out.println(path); // 현재 파일이 위치한 경로 (예: /home/test)
String uploadPath = request.getRealPath("file");
out.println(uploadPath); // 현재 파일이 위치한 경로에 /file 디렉토리가 더해진다. (예ㅣ /home/test/file)
또 다른 절대경로 얻는 법
String saveDir = "/file/";
ServletContext context = getServletContext();
realFolder = context.getRealPath(saveDir);