Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSTL - Print current url including query strings

Tags:

java

jsp

jstl

${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!

like image 386
Tilman Koester Avatar asked Mar 14 '12 14:03

Tilman Koester


2 Answers

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

like image 88
BalusC Avatar answered Nov 09 '22 16:11

BalusC


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:'' }"/>
like image 23
egemen Avatar answered Nov 09 '22 17:11

egemen