18

${requestScope['javax.servlet.forward.servlet_path']} gets me the right string, but not including parameters that might be set in the url.

Example:

http://localhost/path/i/want?param=1 should give me a string /path/i/want?param=1

I have a feeling this should be done easily but can't figure it out.

Thanks in advance!

2 Answers 2

22

It's available by ${requestScope['javax.servlet.forward.query_string']}.

Sign up to request clarification or add additional context in comments.

Comments

12

I have been looking for a while too.

<c:set var="req" value="${pageContext.request}" />
<c:set var="baseURL" value="${fn:replace(req.requestURL, req.requestURI, '')}" />
<c:set var="params" value="${requestScope['javax.servlet.forward.query_string']}"/>
<c:set var="requestPath" value="${requestScope['javax.servlet.forward.request_uri']}"/>
<c:set var="pageUrl" value="${ baseURL }${ requestPath }${ not empty params?'?'+=params:'' }"/>

1 Comment

JSTL was complaining about the += in the tertiary operator so I changed to <c:set var="pageUrl" value="${baseURL}${requestPath}${not empty params ? '?'+params : '' }"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.