Question

Is it possible to get the filename of the jsp file that uses a taglib from the java code?

I.e.

public int doStartTag() throws JspException 
{
    try
    {
        String xxx = pageContext.?

Where xxx would get the filename of the jsp file (which of course could be a nested include file)

br /B

Was it helpful?

Solution

It's not possible to get the name of the JSP file simply because at this point it has been compiled and you're dealing with compiled version rather than source JSP file.

You can get the name of the class JSP has been compiled into via

pageContext.getPage().getClass().getName();

and try to derive the JSP name from it but the naming scheme differs between JSP containers.

OTHER TIPS

You can get the file name and path of the JSP:

String jspFilePath = ((Servlet)pageContext.getPage()).getServletConfig().getServletName();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top