我的代码有什么问题吗?我的if else语句不起作用。
<%
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>
最佳答案
您需要使用.equals方法测试字符串是否相等。
尝试以下方法:
<li <%if(pages.equals("papoy")){out.write("class='active' ");}%>><a href="index.jsp?page=papoy">Papoy</a></li>