基本的に、サイトの完全なドメイン名への URL を構築するカスタム JSP タグを作成しましたhttp://example.com
。問題は、タグ ファイル内に、コードを適切にフォーマットするためのスペースがあり、JSP ファイルでタグを使用すると、これらのスペースが含まれることです。
たとえば、次のようにタグを使用するとします。
<link rel="stylesheet" type="text/css" href="<custom:domainNameUri />${stylesheet}" />
ページのソース コードでは次のように表示されます。
<link rel="stylesheet" type="text/css" href="
http://example.com
/css/bootstrap.css" />
タグの使用時にスペースが出力されないようにするにはどうすればよいですか?
編集:これはタグのソースコードの一部です:
<%@ 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>