Is possible to make output generated by my own JSP tags to be shorter ? For example tag defined as below generate 5 lines instead of 1. Is possible to avoid that (without join all 5 lines into 1 in tag source) ?
<%@ 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>
not a solution:
<%@ 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>
Yes, you can globally configure the JSP parser to trim whitespace which are left by script expressions and tags.
Add this to your webapp’s
web.xml(which has to be Servlet 2.5 compatible!):If you target a Servlet 2.4 container or lower, then you have to edit container’s own
web.xmlinstead to apply this globally. In Tomcat for example, it’s the/conf/web.xmlfile. Search for the<servlet>declaration of theJspServletand add the following servlet init parameter inside the<servlet>declaration.