0

I am trying to find a base url (host, port, context) within the jsp page using EL. I know how to do this on servlet/jsp like this

    StringBuffer url = request.getRequestURL();
    String uri = request.getRequestURI();
    String ctx = request.getContextPath();
    String base = url.substring(0, url.length() - uri.length() + ctx.length()) + "/";

I was searching over the web and found this clue on stackoverflow https://stackoverflow.com/a/2898407/2515808 about expression language.

    ${pageContext.request.contextPath}

Using this I am able to find out the application context path only. Could you please help me find host and port number as well.

Thanks

Community
  • 1
  • 1
Shekhar Sahu
  • 504
  • 1
  • 6
  • 19
  • 1
    Below link might be helpful http://stackoverflow.com/questions/2989888/get-request-url-in-jsp-which-is-forwarded-by-servlet – Snehal Patel Feb 21 '17 at 13:35

1 Answers1

2
${pageContext.request.contextPath} 

Is just calling getContextPath() at request object, to access other things you can do:

${pageContext.request.requestURI} 
${pageContext.request.requestURL} 
${pageContext.request.serverPort}

etc. This way you can call any getter(with no parameters) of request just as you've done in servlet. Also since EL 2.2 you can directly call methods in EL

Dmytro Grynets
  • 923
  • 11
  • 29