VenomFangs VenomFangs - 1 year ago 95
Java Question

JSP Current URL

From some other posts, I was able to get the current URI via:

<%= request.getRequestURL() %>

However the following doesn't work:

<%! String foo = request.getRequestURL(); %>

I'm curious why the above doesn't work, and how to assign the current URI to a string.

Answer Source

Per the javadocs, getRequestURL() returns a StringBuffer, not a String.

Try this instead:

String foo = request.getRequestURL().toString();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download