1

I would like to display "You are not yet friends / you are already friends" after checking the boolean value that comes back from the database rather than "currently friends? false".

Apologies for my inexperience if this is an easy fix

<h1>Here are your friend requests ${sessionScope.LoggedInUser.first_name}</h1>

                </br>

                        <h3>Friend Requests</h3> 
                        <%

                            Statement stat = null;
                            ResultSet res = null;
                            stat = conn.createStatement();
                            String user_id  = request.getParameter("user_id");
                            String data = "select * from user_friendship where user_friends like '%"+user_id+"%'";


                            res = stat.executeQuery(data);
                            while(res.next()){
                        %>
                     <div class="card gedf-card">
                    <div class="card-header" >
                        <div class="d-flex justify-content-between align-items-left">  

                              <div class="dropdown-header justify-content-between align-items-left">
                                <div class="mr-2">
                                    <img class="rounded-circle" width="45" src="https://picsum.photos/50/50" alt="">
                                </div>
                                <!--https://bootsnipp.com/snippets/yNa0V -->


                                <div class="ml-20" >
                                   <div class="h5 m-0">The user <%=res.getInt("user_id") %> wants to be friends</div>
                                   <div class="h6 text-muted">Currently friends? <%= Boolean.parseBoolean("is_accepted")%></div>


                                </div>

                            </div>
                        </div>
                    </div>    
      </div>                   
                        <%
                            }
                         %>
Kelan
  • 11
  • 4
  • You can use `EL` for that check [this](https://stackoverflow.com/questions/3915716/how-to-check-a-boolean-condition-in-el) post. – Swati Feb 05 '20 at 04:31
  • Side note: never EVER use string concatenation to create SQL commands from user input (i.e. `"...where user_friends like '%"+user_id+"%'"`), not even in a school project. This makes your code vulnerable to [SQL Injection](https://www.w3schools.com/sql/sql_injection.asp). Use [PreparedStatement](https://docs.oracle.com/javase/8/docs/api/java/sql/PreparedStatement.html) instead. – Jozef Chocholacek Feb 05 '20 at 07:08
  • @Swati thank you but this does not seem to work with the jsp code that I am currently using, could you provide more detail? – Kelan Feb 06 '20 at 18:48

0 Answers0