【问题标题】:Tomcat 7.0.23 does not work with tag librariesTomcat 7.0.23 不适用于标签库
【发布时间】:2012-01-16 16:22:50
【问题描述】:

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

【问题讨论】:

    标签: jsp jsp-tags tomcat7


    【解决方案1】:

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

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

    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;
    
    }
    

    【讨论】:

      猜你喜欢
      • 2012-06-03
      • 1970-01-01
      • 1970-01-01
      • 2017-07-15
      • 2014-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-25
      相关资源
      最近更新 更多