是否有可能使我自己的JSP標籤生成的輸出更短?例如下面定義的標籤會生成5行而不是1.可以避免這種情況(在標籤源中沒有將所有5行連接到1)?如何縮短自定義JSP標記生成的輸出?
<%@ tag description="link" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ attribute name="href" required="true" type="java.lang.String" %>
<%@ attribute name="label" required="false" type="java.lang.String" %>
<a href="<c:url value="${href}"/>">${not empty label ? label : href}</a>
不是一個解決方案:
<%@ tag description="standard input" pageEncoding="UTF-8"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %><%@ attribute name="href" required="true" type="java.lang.String" description="address relative to web-app context" %><%@ attribute name="label" required="false" type="java.lang.String" description="link label" %><a href="<c:url value="${href}"/>">${not empty label ? label : href}</a>
這是不是其他問題的確切欺騙:一個人如何修剪通過自定義標籤的空白輸出而不只需刪除標籤內的所有空格?您不能在標籤中使用<%@ page trimDirectiveWhitespaces =「true」%>。 – werkshy
正確的答案是可以在標籤中加入:'<%@ tag trimDirectiveWhitespaces =「true」%>' – werkshy
應該重新打開,因爲正確答案(請參閱評論)與原始問題不同。 –