jsp中的Taglib继承:include

时间:2013-04-02 06:40:08

标签: java jsp java-ee taglib

是否可以在其“后代”中继承taglibs或从父JSP中导入?

让我给你举个例子

header.jsp

<%@ page contentType="text/html" isELIgnored="false"
     import="org.something.utils.Constants"%>

//some code, Constants class is available here

index.jsp

<jsp:include page="template/header.jsp" />
//Constants is not available, I get a JasperException: Unable to compile class for JSP

taglibs继承似乎也不起作用。那么有一种方法可以使这项工作吗?

1 个答案:

答案 0 :(得分:1)

Taglibs和import不会被继承,并且标签中的所有内容也不能通过页面继承或传递(JspContext和请求属性除外)。

您有两种选择:

  1. 在您拥有的每个JSP中进行导入。
  2. 使公共类和库成为全局类,这取决于您运行的IDE和服务器。
  3. 修改 定义JSP隐式包括:

    1. For Netbeans http://docs.oracle.com/cd/E19575-01/819-3669/bnajl/index.html
    2. 全球教程http://sabahmyrsh.blogspot.com/2009/06/jsp-defining-implicit-includes.html