简体   繁体   中英

How to check a request parameter in JSP using JSTL, especially <c:set> tag?

I'm trying to parse a request param in my JSP using tags: and

The parameter is namer result, so my variable in jsp is requestScope["result"]

I have two problems exactly: 1) I wanna check two cases: param is null or not, I used the following code

  <c:if test='${not empty requestScope["result"]}'>
    <c:set var = "result" value = '${requestScope["result"] }'/>
  </c:if>
  <c:if test='${empty requestScope["result"]}'>
    <c:set var = "result" value = ' not available'/>
  </c:if>

In order to set the result from request in result variable or "not available" value if it is null

This code always shows not available but when i delete the second test, it shows the result corrctly

Also I tried with '${param.result != null}' test, it gives the same result.

Thank you in advance

我有类似的代码,这种方式适合我:

<c:set var="result" value="${(requestScope['result'] == null || requestScope['result'] eq '') ? 'not available' : ${requestScope['result']}}"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM