Tomcat 7.0.23不适用于标记库

时间:2012-01-16 16:22:51

标签: jsp jsp-tags tomcat7

截至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());

我还写了一个自定义标签,看看它是否正常工作,我也遇到了同样的问题。

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,但我仍然遇到同样的错误。任何建议将不胜感激,谢谢

1 个答案:

答案 0 :(得分:3)

我想出了问题,这是我的jsp。 jsp扩展了一个名为BaseJSPServlet的servlet。默认情况下,当为jsp创建一个java类时,它会扩展org.apache.jasper.runtime.HttpJspBase,但是当你添加一个页面extends指令时,你的java类将扩展你提到的类而不是org.apache.jasper。 runtime.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;

}