Tomcat 7.0.23 不支持标签库

发布于 2024-12-27 07:10:21 字数 2265 浏览 0 评论 0原文

我已经下载了截至 2011 年 1 月 16 日的最新版本的 tomcat 7 即 7.0.23。我发现我的 jakarta 标签库组件都无法在 jsps 中工作。每个jsp 中的故障点都是相同且一致的。我

org.apache.taglibs.input.Select _jspx_th_input_005fselect_005f0 = (org.apache.taglibs.input.Select)_jsp_instancemanager.newInstance("org.apache.taglibs.input.Select", this.getClass().getClassLoader());

还编写了一个自定义标签来查看它是否有效,我对该jsp也遇到了同样的问题。

com.ah.util.customtags.SelectTag _jspx_th_hirezon_005fform_005fselect_005f0 = (com.ah.util.customtags.SelectTag)_jsp_instancemanager.newInstance("com.ah.util.customtags.SelectTag", this.getClass().getClassLoader());

jsp 代码是

<%@ page extends="com.ah.servlets.BaseJSPServlet"%>
<%@ taglib uri="/WEB-INF/hirezon_form.tld" prefix="hirezon_form" %>
<html>
<body>Test tags
<%
System.setProperty("org.apache.jasper.Constants.USE_INSTANCE_MANAGER_FOR_TAGS", "true");
%>
<hirezon_form:select count="100"/>
</body>
</html>

CustomTagSupport 类的代码是

package com.ah.util.customtags;

import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class SelectTag extends TagSupport {

    String count;
    public String getCount() {
        return count;
    }
    public void setCount(String count) {
        this.count = count;
    }
    public int doStartTag() throws JspException {
        // This means the JSP must evaluate the contents of any CHild tags
        // in this tag;
        return EVAL_BODY_INCLUDE;
    }
    // This method is called when the JSP encounters the end of te tag
    // implemented by this class
    public int doEndTag() throws JspException {

        String sum = "200000";
        try {
            pageContext.getOut().write("The Sum of first " + count + " numbers is " + sum);
        } catch (IOException e) {
            throw new JspException("Fatal Error: HelloTag could'nt write to the JSP out");
        }
        // This return type tells the JSP page to continue processing
        // the rest of the page
        return EVAL_PAGE;
    }
}

Tomcat 7.0.23 中是否存在已知错误?我做了很多研究,并尝试将 USE_INSTANCE_MANAGER_FOR_TAGS 属性设置为 true,但我仍然收到相同的错误。任何建议将不胜感激,谢谢

I have downloaded the latest version of tomcat 7 i.e 7.0.23 as of 1/16/2011. I found that none of my jakarta tag library components are working in jsps. The point of failure is same and consistent in every jsp. It is

org.apache.taglibs.input.Select _jspx_th_input_005fselect_005f0 = (org.apache.taglibs.input.Select)_jsp_instancemanager.newInstance("org.apache.taglibs.input.Select", this.getClass().getClassLoader());

I also wrote a custom tag to see if it is working, I had the same problem for that jsp too.

com.ah.util.customtags.SelectTag _jspx_th_hirezon_005fform_005fselect_005f0 = (com.ah.util.customtags.SelectTag)_jsp_instancemanager.newInstance("com.ah.util.customtags.SelectTag", this.getClass().getClassLoader());

The jsp code is

<%@ page extends="com.ah.servlets.BaseJSPServlet"%>
<%@ taglib uri="/WEB-INF/hirezon_form.tld" prefix="hirezon_form" %>
<html>
<body>Test tags
<%
System.setProperty("org.apache.jasper.Constants.USE_INSTANCE_MANAGER_FOR_TAGS", "true");
%>
<hirezon_form:select count="100"/>
</body>
</html>

The code for CustomTagSupport class is

package com.ah.util.customtags;

import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class SelectTag extends TagSupport {

    String count;
    public String getCount() {
        return count;
    }
    public void setCount(String count) {
        this.count = count;
    }
    public int doStartTag() throws JspException {
        // This means the JSP must evaluate the contents of any CHild tags
        // in this tag;
        return EVAL_BODY_INCLUDE;
    }
    // This method is called when the JSP encounters the end of te tag
    // implemented by this class
    public int doEndTag() throws JspException {

        String sum = "200000";
        try {
            pageContext.getOut().write("The Sum of first " + count + " numbers is " + sum);
        } catch (IOException e) {
            throw new JspException("Fatal Error: HelloTag could'nt write to the JSP out");
        }
        // This return type tells the JSP page to continue processing
        // the rest of the page
        return EVAL_PAGE;
    }
}

Is there a known bug in Tomcat 7.0.23? I did a lot of research and also tried setting USE_INSTANCE_MANAGER_FOR_TAGS property to true, but I am still getting the same error. Any suggestions will be appreciated, Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦忆晨望 2025-01-03 07:10:21

我发现问题出在我的jsp上。 jsp 扩展了一个名为 BaseJSPServlet 的 servlet。默认情况下,当为jsp创建java类时,它会扩展org.apache.jasper.runtime.HttpJspBase,但是当您添加页面扩展指令时,您的java类将扩展您提到的类而不是org.apache.jasper。运行时.HttpJspBase。因此,您需要确保您的父类几乎执行 HttpJspBase 类的操作。

以下是可以使用 page extends 指令在 jsp 中扩展的父类的示例代码。

import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.HttpJspPage;
import org.apache.jasper.compiler.Localizer;

public abstract class BaseJSPServlet2 implements javax.servlet.jsp.HttpJspPage

{
  private static final long serialVersionUID = 1L;

  public final void init(ServletConfig config)
    throws ServletException
  {
    super.init(config);
    jspInit();
    _jspInit();
  }

  public String getServletInfo()
  {
    return Localizer.getMessage("jsp.engine.info");
  }

  public final void destroy()
  {
    jspDestroy();
    _jspDestroy();
  }

  public final void service(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
  {
    _jspService(request, response);
  }

  public void jspInit()
  {
  }

  public void _jspInit()
  {
  }

  public void jspDestroy()
  {
  }

  protected void _jspDestroy()
  {
  }

  public abstract void _jspService(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws ServletException, IOException;

}

I figured out the problem, it was my jsp. The jsp extends a servlet called BaseJSPServlet. By default when a java class is created for jsp, it extends org.apache.jasper.runtime.HttpJspBase, but when you add a page extends directive, your java class will be extending the class you mentioned instead of org.apache.jasper.runtime.HttpJspBase. So you need to make sure that your parent class does pretty much what HttpJspBase class does.

Here is the sample code of a parent class that can be extended in jsp using page extends directive.

import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.HttpJspPage;
import org.apache.jasper.compiler.Localizer;

public abstract class BaseJSPServlet2 implements javax.servlet.jsp.HttpJspPage

{
  private static final long serialVersionUID = 1L;

  public final void init(ServletConfig config)
    throws ServletException
  {
    super.init(config);
    jspInit();
    _jspInit();
  }

  public String getServletInfo()
  {
    return Localizer.getMessage("jsp.engine.info");
  }

  public final void destroy()
  {
    jspDestroy();
    _jspDestroy();
  }

  public final void service(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
  {
    _jspService(request, response);
  }

  public void jspInit()
  {
  }

  public void _jspInit()
  {
  }

  public void jspDestroy()
  {
  }

  protected void _jspDestroy()
  {
  }

  public abstract void _jspService(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws ServletException, IOException;

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文