So you want the URL of the page which called the current page by a fullworthy HTTP request? I assume that there's no means of a forward, because you usually don't use JSP for this (as it would potentially produce IllegalStateException: Response already committed
) and also, with a forward your requirement would have just worked the way you want.
The easiest way and your best bet is then getting the HTTP Referer
header (yes, including the legendary typo). You can get it in EL as follows:
${header.referer}
I said "best bet", because clients are not required to fill the referrer header. Most browsers will send them along, but keep in mind that this value is fully controllable by the client, thus the client (or any of the client-installed software, with some specific Norton software as known example) can spoof or even fully remove the header value.
A bit more reliable way is to let the original page pass its URL as a (hidden) request parameter. E.g.
<input type="hidden" name="from" value="${pageContext.request.requestURI}">
This way it's accessible in next page by
${param.from}
I said, "bit", because the client can still change it, but now you're not dependent on the client specific environment anymore. You still need to keep in mind that you shouldn't use this value for business purposes. Use it at highest for statistics or debugging.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…