How do I get the name of the currently executing script?
Created May 4, 2012
Alex Chaffee
encodeURL adds session information if necessary. See the
Sun Servlet Tutorial and this FAQ's Session Tracking
question. Note that this method was renamed from
"encodeUrl " to the properly-capitalized
"encodeURL " somewhere around version 2.1 of the servlet
spec.)
Use
URL |
|
---|---|
getRequestURI |
|
getServletPath |
|
getPathInfo | |
getQueryString |
This is useful if your form is self-referential; that is, it generates a form which calls itself again. For example:
out.println("<FORM METHOD=POST ACTION="" + res.encodeURL(req.getServletPath()) + "">"); out.println("<INPUT NAME=value>"); out.println("<INPUT TYPE=submit>"); out.println("</FORM>");(
Note that early versions of Java Web Server and some servlet engines
had a bug whereby