0

for example,my own website is xxx.com. I want to get this domain in jsp or jstl. ${pageContext.request.contextPath} just returns "/". I tried this:

<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="req" value="${pageContext.request}" />
<c:set var="url">${req.requestURL}</c:set>
<c:set var="uri" value="${req.requestURI}" />
${fn:substring(url, 0, fn:length(url) - fn:length(uri))}

but it returns 127.0.0.1,not domain like xxx.com

maazza
  • 7,016
  • 15
  • 63
  • 96
  • keep `${fn:substring(url, 0, fn:length(url) - fn:length(uri))}` inside `` tag – Rahman Nov 12 '15 at 17:02
  • try to use this link i guess is useful [http://stackoverflow.com/questions/6271075/how-to-get-the-base-url-from-jsp-request-object](http://stackoverflow.com/questions/6271075/how-to-get-the-base-url-from-jsp-request-object) – Abdelhak Nov 12 '15 at 17:09

0 Answers0