Front/JSP

[JSP] JSP에서 데이터를 가져오는 여러가지 방법

AlexHouse 2022. 11. 29. 11:34
728x90

 

바로 들어가보자.

 

 


 

getContextPath()

 


프로젝트 Path만 가져온다.

request.getContextPath() 

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

[return]/project 

 

 

 

getRequstURI()

 

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

request.getRequestURI() 

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

[return]        /project/list.jsp  

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

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



 

getRequestURL()

 

전체 경로를 가져온다. 

request.getRequestURL()

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

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



 

 

ServletPath()

 

파일명만 가져온다.

request.ServletPath() 

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

[return] /list.jsp

 

 

getRealPath()

 

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

request.getRealPath() 

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

[return]         c:\project\webapps\

 

 


 

To be continue..

728x90

'Front > JSP' 카테고리의 다른 글

[JSP] getContextPath 사용방법  (0) 2022.11.29