I'm in the process of developing an online computer store and need to create a login JSP for both admin and regular users. One challenge I'm facing is how to loop through my ArrayList of users and display a specific chunk of code if the user has the attribute isLoggedIn == true
.
<a class="whiteOff" href="AdminLogin?logoff">Izloguj se (<%=k.getIme() %>)</a>
<a class="hide" href="register.jsp">Registracija</a>
<a class="hide" href="adminLogin.jsp">Logovanje za administratore</a>
<a class="hide" href="userLogin.jsp">Logovanje za korisnike</a><br/>
If the isLoggedIn == false
, then another set of code should be displayed.
<a class="hide" href="AdminLogin?logoff">Izloguj se (<%=k.getIme() %>)</a>
<a class="white" href="register.jsp">Registracija</a>
<a class="white" href="adminLogin.jsp">Logovanje za administratore</a>
<a class="white" href="userLogin.jsp">Logovanje za korisnike</a><br/>
In my JSP file, I've implemented this logic using a loop over the list of users:
<%for(Korisnik k : Baza.getUser()){%>
<% if(k.loggedIn){%>
<a class="whiteOff" href="AdminLogin?logoff">Izloguj se (<%=k.getIme() %>)</a>
<a class="hide" href="register.jsp">Registracija</a>
<a class="hide" href="adminLogin.jsp">Logovanje za administratore</a>
<a class="hide" href="userLogin.jsp">Logovanje za korisnike</a><br/>
<% } else{%>
<a class="hide" href="AdminLogin?logoff">Izloguj se (<%=k.getIme() %>)</a>
<a class="white" href="register.jsp">Registracija</a>
<a class="white" href="adminLogin.jsp">Logovanje za administratore</a>
<a class="white" href="userLogin.jsp">Logovanje za korisnike</a><br/>
<% } %>
<% } %>
The issue arises when registering new users, causing duplicate links for each registered user. To address this, I'd like to display the specified code at the top only once when the loggedIn attribute is true for any user, avoiding repetition based on the number of registered users logged in.