JSPs

https://en.wikipedia.org/wiki/Jakarta_Server_Pages

How conditionally show the content of a div rather than another div in a JSP page?

https://stackoverflow.com/questions/27273220/how-conditionally-show-the-content-of-a-div-rather-than-another-div-in-a-jsp-pag

If into a JSP page I have 2 div like this:

<div id="succes">
    <p>SUCCESS</p>
</div>
<div id="failure">
    <p>FAILURE</p>
</div>

If we have to show only one of these divs according to the value of some other variable, how to do it?

With JSPs the right way to do it is using JSTL tags.

<c>:choose>
    <c:when test= "${request.getSession().getAttribute("userName").equals("Guest")}">
        <div> Welcome Guest</div>
    </c:when>
    <c:otherwise>
        <div> Welcome Real User</div>
    </c:otherwise>
</c:choose>

Gotchas

  1. JSP runs on the server, generating html that is then sent to the browser, while Dojo executes entirely in the user’s browser as JavaScript code.
  2. JSTL will work only if the logic is run in the server side code.
  3. JSTL will not work if it is put in html or dojo code.
  4. html and dojo rendering is done in the browser - completely client-side.
  5. See How to disable selection options using JavaScript?

Tags

  1. Dojo Toolkit

Links to this note