lundi 27 juin 2016

If-else statement not working properly

My website is just like SO. In this page I am trying to retrieve answered and unanswered questions in two separate tables. But in output I am getting both answered and unanswered questions being displayed in Answered Questions table. What is going wrong here ? I appreciate all help and effort. Here is my code :-

<%@page import="model.QuestionBean"%>
<%@page import="java.util.List"%>
<%@page import="model.QuestionDAO"%>
<%@page import="model.QuestionDAOFactory"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>All Questions</title>
    </head>
    <body>
        <div>



                    <%
                    QuestionDAOFactory qdf=new QuestionDAOFactory();
                    QuestionDAO qd=qdf.createQuestionDAO();
                    List<QuestionBean> list=qd.getQuestions();
                    for (QuestionBean qb : list) {
                    %>

                        <%
                        if(qb.getIsAnswered().equalsIgnoreCase("Y"))
                        %>
                        <table style="width: 50%;height: 100%;border: 1px solid black;" align="">
                            <thead>
                                <tr>
                                    <th>Answered Questions</th>
                                </tr>
                            </thead>
                            <tbody>
                                <%
                                    {
                                %>
                            <tr><td><a href="viewQuestion.jsp?id=<%=qb.getQuestionId() %>"><%=qb.getQuestionText() %></a></td></tr>
                                <%
                                    }
                                %>
                            </tbody>
                        </table>    
                        <%
                            else
                        %>
                        <table style="width: 50%;height: 100%;border: 1px solid black;" align="">
                            <thead>
                                <tr>
                                    <th>Unanswered Questions</th>
                                </tr>
                            </thead>
                            <tbody>
                                <%
                                    {
                                %>
                            <tr><td><a href="viewQuestion.jsp?id=<%=qb.getQuestionId() %>"><%=qb.getQuestionText() %></a></td></tr>
                                <%
                                    }
                                %>
                            </tbody>
                        </table>


                    <%
                        }
                    %>

            </table>
        </div>
    </body>
</html>

Aucun commentaire:

Enregistrer un commentaire