2012-12-08 52 views
1

我有我的所有JSP禁用小腳本在web.xml:導入自定義標籤庫

<jsp-config> 
    <jsp-property-group> 
     <url-pattern>*.jsp</url-pattern> 
     <scripting-invalid>true</scripting-invalid> 
    </jsp-property-group> 
</jsp-config> 

但我需要導入正在使用類似這樣的一些自定義標籤庫:

<%@ taglib prefix="utils" uri="/tags-utils" %> 

如何做,而無需使用小腳本我導入? 另外,如何避免使用以下內容?

<%@ page language="java" contentType="text/html; charset=UTF-8" %> 

scriptlet移除的決定是爲了避免由多個開發人員編寫的項目中的scriptlet混亂。

如果無法使用scriptlet更改導入,那麼除非<%@ taglib<%@ page以外的其他用途,我將如何禁用它?

試圖從

<%@ taglib prefix="s" uri="/struts-tags" %> 

改變

<jsp:directive.tagLib prefix="s" uri="struts-tags" /> 

但Servlet的引發我一個錯誤:

[org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/portal].[jsp]] (http-localhost-127.0.0.1-80-3) Servlet.service() for servlet jsp threw exception: org.apache.jasper.JasperException: /index.jsp(2,18) <jsp:directive.tag directive can only be used in a tag file

還有什麼我有什麼關係?

回答

2

JSP 2.2規格

JSP 1.3.10.1 EBNF語法對語法JSP

ScriptlessBody ::= ((‘<%--’ JSPCommentBody) 
        | (‘<%@’ DirectiveBody) 
        | (‘<jsp:directive.’ XMLDirectiveBody) 
        | (‘<%!’ <TRANSLATION_ERROR>) 
        | (‘<jsp:declaration’ <TRANSLATION_ERROR>) 
        | (‘<%=’ <TRANSLATION_ERROR>) 
        | (‘<jsp:expression’ <TRANSLATION_ERROR>) 
        | (‘<%’ <TRANSLATION_ERROR>) 
        | (‘<jsp:scriptlet’ <TRANSLATION_ERROR>) 
        | (‘${‘ ELExpressionBody) 
        | (‘#{‘ ELExpressionBody) 
        | (‘<jsp:text’ XMLTemplateText) 
        | (‘<jsp:’ StandardAction) 
        ((‘</’ ExtraClosingTag) 
        | (‘<‘ CustomAction CustomActionBody) 
        | TemplateText 
        )* 

所以,當scripting-invalid=true

非法

<% 
<%! 
<%= 
<jsp:scriptlet 
<jsp:declaration 
<jsp:expression 

法律

<%@ 
<jsp:directive. 
<jsp: 

以下是合法的:

<%@ taglib prefix="utils" uri="/tags-utils" %> 

只要「app context uri」+「/ tags-utils」(taglib的上下文相關路徑)映射到「taglib absolute uri」。

或者,你可以嘗試:

<%@ taglib prefix="utils" uri="http://www.mycorp/utiltags" %> // use your absolute taglib URI 

OR

<%@ taglib prefix="utils" uri="uri_path_relative_to_jsp_uri" %> // no leading "/" 

OR

<%@ taglib prefix="utils" tagdir="/WEB-INF/tags" %> // include subdir if approp 

以下是發明的。沒有定義jsp:directive.tagLib標籤。不要使用。

<jsp:directive.tagLib prefix="s" uri="struts-tags" /> 

相反的:

<%@ page language="java" contentType="text/html; charset=UTF-8" %> 

嘗試:

<%@ page contentType="text/html; charset=UTF-8" %> // language is for scriptlets 
+0

正是我需要的 –

-1

<%@taglib<%@page是指令,而不是scriptlet。

Scriptlets將有<%

或者,你可以這樣寫

<jsp:directive.taglib uri="uri" prefix="prefixOfTag" /> 
+0

「的腳本

+0

@FagnerBrack,不,你錯了。有兩種方法來聲明任何jsp元素,一個是舊的<%... style,另一個是

+0

當我使用該指令使用標記時,它不會在eclipse上自動完成,並引發錯誤:「(http -localhost-127.0.0.1-80-5)用於servlet jsp的Servlet.service()拋出異常:org.apache.jasper.JasperException:/index.jsp(2,18)