I wrote a custom JSP tag that basically constructs a URL to the full domain name of my site, e.g. http://example.com
. The problem is that within my tag file, I have spaces to properly format my code, and these spaces are included when I use the tag in JSP files.
For example, if I use my tag like this:
<link rel="stylesheet" type="text/css" href="<custom:domainNameUri />${stylesheet}" />
It will show up like this in the page's source code:
<link rel="stylesheet" type="text/css" href="
http://example.com
/css/bootstrap.css" />
How do I prevent spaces from being output from my tag so it doesn't break things when I use the tag?
Edit: Here is part of the tag's source code:
<%@ attribute name="includePort" required="false" type="java.lang.Boolean" description="Whether or not to include the server port in the URI" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="domain" value="${pageContext.request.serverName}" />
<%-- Build domain name URI --%>
<c:set var="uri" value="${pageContext.request.scheme}://${domain}" />
<c:choose>
<c:when test="${includePort == true}">
<c:out value="${uri}:${pageContext.request.serverPort}" />
</c:when>
<c:otherwise>
<c:out value="${uri}" />
</c:otherwise>
</c:choose>