在我的 .jsp 文件中,我有以下代码。如何将environment
变量与字符串进行比较?Netbeans 不喜欢这个……我试过添加scope="request"
,但c:set
没有运气。
<c:set var="environment" value="<%=(request.getRequestURL().indexOf("localhost") > 0) ? "dev" : "uat"%>"/>
<% if (environment.equals("live")) { %>
有什么特别的原因您不会完全在 scriptlet 中执行此操作吗?如果它是在 scriptlet 中定义的,您仍然可以在 JSTL 中访问该变量
<% String environment = (request.getRequestURL().indexOf("localhost") > 0) ? "dev" : "uat"; %>
<% if (environment.equals("live")) { %>
<c:out value="${environment}"/>
看看这里: http: //melandri.net/2009/09/16/scriptlet-and-jstl-variable-sharing/
您也可以完全在 JSTL 中执行以下操作:
<c:set var="environment" value="${(fn:indexOf(request.requestURL, 'localhost') gt 0) ? 'dev' : 'uat'}"/>