【问题标题】:Retain the status of checkbox in search after validation or search验证或搜索后保留搜索中复选框的状态
【发布时间】:2014-02-11 08:06:26
【问题描述】:

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

感谢您的帮助。

【问题讨论】:

  • 您是否尝试过相同的复选框或您尝试过的其他方法
  • @prash 我和

标签: html forms jsp checkbox struts


【解决方案1】:

我试过这样的 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>

希望这会有所帮助。请告诉我。

【讨论】:

  • 是的,我正在寻找一个没有 JSTL 标签的选项,它工作正常。谢谢你,我很感激你的帮助。我应该更具体一些,但您在提供这两个选项时的周到节省了很多时间,让我很开心。谢谢。
猜你喜欢
  • 2016-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-12
相关资源
最近更新 更多