Web tier: servlets, JSP, Web frameworks: how can i determine the current URL in a jsp page?
i know in PHP, there's a static constant called PHP_SELF which stores the current URL. is there an equivalent of this for JSP?
- Posted by: Shawn Wall
- Posted on: April 10 2001 13:59 EDT
- how can i determine the current URL in a jsp page? by Pradeep Nair on April 10 2001 20:24 EDT
- how can i determine the current URL in a jsp page? by J Dev on March 25 2011 07:58 EDT
JSP on compilation generates a servlet thus the request, response objects are readily available.
The following scriptlet (Java code) should give you what you need
<%= request.getRequestURI() %>
This will print the URI to the browser. If you want to store it in a variable use the following
<% String myURI = request.getRequestURI(); %>
If you need the value as a URL you will need to use the following
<%@ page import="javax.servlet.http.HttpUtils.*" %>
<%= javax.servlet.http.HttpUtils.getRequestURL(request) %>
in the JSP.
you can getRequestURI() and getRequestURL() functions. See Servlet request for more details about the request methods