2014-02-07 40 views
1

我有一个搜索页面,其中包含各种搜索条件选项,包括复选框。 我想保留搜索条件的状态,以便使用应用程序的人知道他们搜索的内容。 我正在使用<input type="text" name="foo" value="${param.foo}">作为文本框,但我不知道如何处理复选框。在验证或搜索后保留搜索框中的复选框状态

我将不胜感激您的帮助。

+0

您是否尝试过相同的复选框或您尝试过的其他方法 – spiderman

+0

@prash我尝试了相同的方法以及 user3284391

回答

0

我试着用这样的JSTL标签库,

<c:if>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<html> 
<head> 
<title>Employee Search</title> 
</head> 
<body> 

    <font size="+1"> Search </font> 
    <form action="search.jsp" method="GET"> 
     <table> 
      <tr> 
       <td align="right">Name:</td> 
       <td><input type="text" name="name" value="${param.name}" /></td> 
      </tr> 
      <tr> 
       <td align="right">Location:</td> 
       <td><input type="checkbox" name="location" value="france" 
        <c:if test="${param.location != null && param.location=='france' }"> 
       checked='checked' 
       </c:if>>france<br> 
       </td> 
      </tr> 
      <tr> 
       <td></td> 
       <td><input type="submit" /></td> 
      </tr> 
     </table> 
    </form> 
</body> 
</html> 

注意:请不要忘记将在的jstl.jar WEB-INF/lib目录下。你可以从here

下载现在,如果你不希望使用JSTL标签[我认为这是一个你正在寻找],你可以这样做,

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<html> 
<head> 
<title>Employee Search</title> 
</head> 
<body> 
    <font size="+1"> Search</font> 
    <form action="search.jsp" method="GET"> 
     <table> 
      <tr> 
       <td align="right">Name:</td> 
       <td><input type="text" name="name" value="${param.name}" /></td> 
      </tr> 
      <tr> 
       <td align="right">Location:</td> 
       <td><input type="checkbox" name="location" value="france" 
       ${param.location=='france' ? 'checked=checked' : ''} 
       >france<br> 
       </td> 
      </tr> 
      <tr> 
       <td></td> 
       <td><input type="submit" /></td> 
      </tr> 
     </table> 
    </form> 
</body> 
</html> 

希望这有助于。请告诉我。

+0

是的,我正在寻找一个没有JSTL标签的选项,它工作正常。谢谢你,我感谢你的帮助。我应该更具体一些,但是在给予这两种选择方面你的想法可以节省很多时间并让我有一天。谢谢。 – user3284391

+0

@ user3284391欢迎您。 – spiderman