Is it possible to get the name of the page being called inside a jsp 2.0 custom tag?
It is possible to access the request from a tag file through a member variable pageContext
.
public class YourTag extends TagSupport {
public int doStartTag() throws JspException {
HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
String pathInfo = req.getPathInfo();
source to share
The request object is available in the tag. It doesn't matter if you are using a class or a tag file. In tag files, it is available in Java scripts as well as EL. However, it is available as a ServletRequest object, not an HttpServletRequest object (in EL, the class of the object does not matter, but it is executed in scripts).
Also, in your scripts, you need to access the full method, not just the property name. Thus, your code should be:
<form action="<%= pageContext.getRequest().getRequestURI() %>">
but even that won't work because getRequestURI () is the HttpServletRequest [1] method, not the ServletRequest. So either use EL or use longer scriptlets in your tag file and cast the request object.
[1] http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpServletRequest.html#getRequestURI ()
source to share