简体   繁体   中英

Can you get the filename of the jsp file using a taglib in the taglib code

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

Ie

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

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.

您可以获取JSP的文件名和路径:

String jspFilePath = ((Servlet)pageContext.getPage()).getServletConfig().getServletName();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM