0

I am trying to check that attribute in http session storage called "username" is there/not there in http session storage. If it is in http session storage it will show a button. If is not in http session storage the button should not be shown.

I have tried the following methods, both do not seem to work

First method: Review button shows up when "username" both when "username" is in http storage and not in http storage

<%
                String username1 = (String) session.getAttribute("username");
                
                %>
                <c:if test = "${username1.length()!=0}">
                    <button class="btn btn-primary" style="background-color: #887775; border: none;" id="myBtn">Write a review</button>
                </c:if> 

Second method: Review button does not show up at all whether "username" is there or not there in http session storage

<%
                String username1 = (String) session.getAttribute("username");
                
                %>
                <c:if test = "${username1.isEmpty()==true}">
                    <button class="btn btn-primary" style="background-color: #887775; border: none;" id="myBtn">Write a review</button>
                </c:if> 

Any help will be appreciated!

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Are there any exceptions in your log? Can you try `request.getSession().getAttribute("username")`? – Felix Schildmann Jan 08 '23 at 10:28
  • Please completely stop using old fashioned Scriptlet `<%...%>`. These variables are not available in EL `${...}` at all and mixing the Scriptlet and EL approaches will only confuse yourself for nothing. Just use `${not empty username}` right away. – BalusC Jan 09 '23 at 12:36

0 Answers0