Java – how to get the URL of the client

I will request from display JSP to trialshow JSP page, but whenever I call ${pageContext.request.requestURL} on TrialShow JSP page, I will receive http:// localhost:8081 / newjsp1 / TrialShow.. JSP as output How to display http: / / localhost: 8081 / newjsp1 / display in the trialshow JSP page jsp?

Solution

So you want a URL that calls the current page through a complete HTTP request? I assume that there is no forward method, because you usually don't use JSP (because it may produce IllegalStateException: the response has been submitted), and if you have a forwarding, your requirements will run as you want

The easiest way and best choice is to get the HTTP referer title (yes, including legendary spelling mistakes) You can get it in El as follows:

${header.referer}

I say "the best choice" because customers don't need to fill in referrals to the source Most browsers send them, but remember that this value is completely controlled by the client, so the client (or any client installed software, and some specific Norton software as known examples) can spoof or even completely delete the header value

A more reliable way is to have the original page pass its URL as a (hidden) request parameter For example

<input type="hidden" name="from" value="${pageContext.request.requestURI}">

So it can be accessed on the next page

${param.from}

I say "bit" because the client can still change it, but now you are no longer dependent on the client specific environment You still need to remember that this value should not be used for business purposes Use it for statistics or debugging

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>