HashSet
次のコードで作成された文字列があります。
Set<String> scripts = new HashSet<>();
String contextPath = request.getContextPath();
scripts.add(contextPath + "/resources/scripts/jquery.cycle2.js");
scripts.add(contextPath + "/resources/scripts/jquery.cycle2.center.js");
scripts.add(contextPath + "/resources/scripts/slideshow.js");
request.setAttribute("scripts", scripts);
JSP ページで、JSTL を使用して、通常の forEach ループを実行します。
<c:if test="${not empty scripts}">
<c:forEach var="script" items="${scripts}" >
<script type="text/javascript"
src="${script}">
</script>
</c:forEach>
</c:if>
ページをロードすると、次のようになります。
<script type="text/javascript"
src="[/InfoKiosk/resources/scripts/jquery.cycle2.center.js">
</script>
<script type="text/javascript"
src=" /InfoKiosk/resources/scripts/jquery.cycle2.js">
</script>
<script type="text/javascript"
src=" /InfoKiosk/resources/scripts/slideshow.js]">
</script>
最初のスクリプト ソースの前と最後のスクリプト ソースの後にある角かっこ([
と) に注意してください。]
彼らはどこから来たのか?