JSTL) get current URL(URI) / jstl로 현재 URL(URI) 가져오기

북마크 추가

전체 url이 http://trandent.com/board/Spring/detail/774 인 경우 

1. domain 가져오기

 

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<c:set var="baseURL" value="${fn:replace(req.requestURL, fn:substring(req.requestURI, 0, fn:length(req.requestURI)), req.contextPath)}" />

 

-> ${baseURL} = http://trandent.com

 

2. path 가져오기

<c:set var="path" value="${requestScope['javax.servlet.forward.servlet_path']}" /> 

-> ${path} = /board/Spring/detail/774

 

3. result

${baseURL}${path} = http://trandent.com/board/Spring/detail/774

 

HKH
2018-02-26 11:59
SHARE
keyboard_arrow_left
keyboard_arrow_up