Oleksandr Bondarenko
Oleksandr Bondarenko

Reputation: 2018

Where can the variable in jsp be defined except java classes?

Suppose I have the following code:

<c:when test="${isFoo}">

Where can isFoo be defined except:

  1. java classes
  2. <c:set ... /> construction ?

Upvotes: 1

Views: 273

Answers (2)

BalusC
BalusC

Reputation: 1108852

  1. In JSP itself by scriptlets. E.g. as a request attribute:

    <% request.setAttribute("isFoo", true); %>
    

    Scriptlets are however discouraged since over a decade.


  2. By an implicit EL variable. E.g. as a request parameter:

    http://example.com/page.jsp?isFoo=true

    Which can be accessed by ${param}:

    <c:if test="${param.isFoo}">
    

    There are many more, you can find them all in this overview.


See also:

Upvotes: 1

CoolBeans
CoolBeans

Reputation: 20800

You can also set it using c:set. For instance:

<c:set var="isFoo" value="true" scope="page" />

Upvotes: 2

Related Questions