JSP 자바 코딩에서 다양한 url 주소 가져오는 함수를정리할게요 ㅎ

 

프로젝트 Path만 가져옵니다.

request.getContextPath() 

예)  http://localhost:8080/project/list.jsp

[return]/project 

 

프로젝트 + 파일경로까지 가져옵니다.

request.getRequestURI() 

예)  http://localhost:8080/project/list.jsp

[return]        /project/list.jsp  

String url = request.getRequestURI.split("/");

String Name = url[url.length -1];       // list.jsp

 

전체 경로를 가져옵니다. 

request.getRequestURL()

예) http://localhost:8080/project/list.jsp

[return]   http://localhost:8080/project/list.jsp

 

파일명만 가져옵니다.

request.ServletPath() 

예) http://localhost:8080/project/list.jsp

[return] /list.jsp

 

서버 or 로컬 웹 애플리케이션 절대결로 가져옵니다. 

request.getRealPath() 

예) http://localhost:8080/projectname/list.jsp

[return]         c:\project\webapps\projectname\

 
 

 

 
 

'프로그래밍 > JSP' 카테고리의 다른 글

servletContextListener 만들기  (0) 2015.05.21
DAO 만들기  (0) 2015.05.21
GET방식 POST방식 인코딩 처리하기  (2) 2015.04.05

+ Recent posts