Seth Banks wrote:

> Hey guys,
>
> If I wanted to get the current URL string for the page that I am writing
> code for, how would I go about this? I'm guessing it's something from the
> servlet classes?
>
> Thanks!
>
> // seth banks
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> FAQs on JSP can be found at:
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html

Yep,

<%
    String requestURI = request.getRequestURI();
%>

or, if you only want to display it:

    <%= request.getRequestURI() %>

This will give you back the part of the request after the
http://www.mycompany.com:port part, which is all you usually need.  There's a
utility method in HttpUtils to reconstruct the entire URL (including any query
string) if you want that instead.

Because your JSP page is a servlet, it can use the entire servlet API.  A place
where this is particularly important, for example, is encoding URL hyperlinks so
that session management works even if the client browser has cookies turned off:

    <a href="<%= response.encodeURL("menu.jsp")>">Main Menu</a>


Craig McClanahan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to