Mohammed ESSABRI
Mohammed ESSABRI

Reputation: 88

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: <c:if> and <c:set>

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

I have two issues:

  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

Upvotes: 0

Views: 4411

Answers (1)

Jumper
Jumper

Reputation: 41

I have similiar code and this way works for me:

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

Upvotes: 1

Related Questions