我有JSP页面,在jsp页面上我有这个:
<c:when test="${empty findAttributes && param.value1 != null}">
<h1 align="center"><spring:message code="label.msg"/></h1>
</c:when>
而不是param.value1 !=null
我必须使用param.value1 !=""
,但它不起作用,给我一个错误。请帮助使其正确无误。
答案 0 :(得分:2)
正确的方法是使用empty
关键字。这包括无效和空虚。
<c:when test="${empty findAttributes && empty param.value1}">
如果根本没有提供参数名value1
(然后评估为null
而不是为空字符串),您的情况仍会失败。请求参数仅在提供参数名称时评估为空字符串,而不是像value0=foo&value1=&value2=bar
那样的值。但是,如果请求参数完全不存在value0=foo&value2=bar
,那么它的计算结果为null
,这与空字符串不同。
答案 1 :(得分:0)
您应该使用JSTL的empty
运算符,而不是使用!=
<c:when test="${empty findAttributes && empty param.value1}">
来自2.1规范:
评估空A: