How do I get the name of the currently executing script?
Created Sep 3, 1999
Alex Chaffee
This is useful if your form is self-referential; that is, it generates
a form which calls itself again. For example:
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 |
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