简体   繁体   English

您可以使用taglib代码中的taglib获取jsp文件的文件名

[英]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? 是否有可能从java代码获取使用taglib的jsp文件的文件名?

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) 其中xxx将获取jsp文件的文件名(当然可以是嵌套的包含文件)

br /B 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. 获取JSP文件的名称是不可能的,因为此时它已被编译并且您正在处理已编译的版本而不是源JSP文件。

You can get the name of the class JSP has been compiled into via 您可以通过JSP获取已编译的类的名称

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

and try to derive the JSP name from it but the naming scheme differs between JSP containers. 并尝试从中派生JSP名称,但JSP容器之间的命名方案不同。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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