2012-01-16 73 views
1

我已經下載了截至2011年1月16日的最新版本的tomcat 7,即7.0.23。我發現我的jakarta標記庫組件都不在jsps中工作。每個jsp中的失敗點都是一樣的和一致的。這是Tomcat 7.0.23不能與標籤庫一起工作

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一個已知的bug?我做了大量的研究,並嘗試將USE_INSTANCE_MANAGER_FOR_TAGS屬性設置爲true,但我仍然遇到同樣的錯誤。任何建議將不勝感激,謝謝

回答

3

我想出了問題,這是我的jsp。 jsp擴展了一個名爲BaseJSPServlet的servlet。默認情況下,當爲jsp創建一個java類時,它會擴展org.apache.jasper.runtime.HttpJspBase,但是當您添加頁面extends指令時,您的java類將擴展您提到的類而不是org.apache.jasper。 runtime.HttpJspBase。所以你需要確保你的父類幾乎完成了HttpJspBase類的功能。

以下是可以使用頁面擴展指令在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; 

} 
相關問題