Is there anything wrong with my code? My if else statement is not working.
<% String pages = request.getParameter("page"); %> <input type="hidden" id="page" value="<%=pages%>"/> <div class="navbar navbar-fixed-bottom"> <div class="navbar-inner"> <a class="brand" href="index.jsp">PeachMangoPie</a> <ul class="nav pull-right"> <li <%if(pages=="papoy"){out.write("class='active' ");}%>><a href="index.jsp?page=papoy">Papoy</a></li> <li class="divider-vertical"></li> <li <%if(pages=="chuckie"){out.write("class='active' ");}%>><a href="index.jsp?page=chuckie">Chuckie</a></li> <li class="divider-vertical"></li> <li <%if(pages=="dutchmill"){out.write("class='active' ");}%>><a href="index.jsp?page=dutchmill">Dutch Mill</a></li> <li class="divider-vertical"></li> <li <%if(pages=="icecream"){out.write("class='active' ");}%>><a href="index.jsp?page=icecream">Ice Cream</a></li> <li class="divider-vertical"></li> <li <%if(pages=="chicken"){out.write("class='active' ");}%>><a href="index.jsp?page=chicken">Chicken</a></li> <li class="divider-vertical"></li> <li <%if(pages=="straberrycake"){out.write("class='active' ");}%>><a href="index.jsp?page=strawberrycake">Strawberry-Cake</a></li> </ul> </div> </div>
Advertisement
Answer
You need to use the .equals method to test for string equality. Try this instead:
<li <%if(pages.equals("papoy")){out.write("class='active' ");}%>><a href="index.jsp?page=papoy">Papoy</a></li>