简体   繁体   English

jsp:include中的Taglib继承

[英]Taglib inheritance in jsp:include

Is it possible to inherit taglibs or imports from parent JSPs in their "descendants"? 是否可以从父JSP的“后代”继承taglib或导入?

Let me show you an example 我举个例子

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

also the taglibs inheritance doesn't seem to work. 同样,taglibs继承似乎不起作用。 So is there a way how to make this work? 那么有没有办法使这项工作呢?

Taglibs and imports are not inherited, and everything in a tag as well cannot be inherited or passed through pages (except for JspContext and request attributes). Taglib和导入不会被继承,并且标记中的所有内容也不能被继承或通过页面传递(JspContext和request属性除外)。

You have two options here: 您在这里有两个选择:

  1. Make the import in every JSP you have. 在您拥有的每个JSP中进行导入。
  2. Make the common classes and libraries Global ones, this depends on the IDE and the server you are running. 使通用的类和库成为全局类和库,这取决于IDE和您正在运行的服务器。

Edit Defining JSP implicit includes: 编辑定义JSP隐式包括:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM