Jsp 如何将下拉列表中的选项传递到foreach中的数据bean方法中

Jsp 如何将下拉列表中的选项传递到foreach中的数据bean方法中,jsp,Jsp,免责声明:我对JSP完全陌生,所以我正在寻找一个简单的解决方案来解决这个问题 我有一些JSP,它创建了一个HTML表。顶部有一个标题,然后是个人标题 从数据bean中检索行,并为循环中创建的每一行检索HTML 下面是JSP的一个简短片段 <table width="100%" cellpadding="3"> <tr style="vertical-align:center;"> <th> Event </th>

免责声明:我对JSP完全陌生,所以我正在寻找一个简单的解决方案来解决这个问题

我有一些JSP,它创建了一个HTML表。顶部有一个标题,然后是个人标题 从数据bean中检索行,并为循环中创建的每一行检索HTML

下面是JSP的一个简短片段

<table width="100%" cellpadding="3">
<tr style="vertical-align:center;">
    <th>
        Event
    </th>
    <th>
        Scheduled
    </th>
    <th>
        Due Date
    </th>
    <th>
        Status&nbsp;
        <select name="statusFilter" onChange="location.reload()">
            <c:forEach var="filter" items="${dataBean.getStatusFilters()}">
                <option value="${filter}">${filter}</option>
            </c:forEach>
        </select>
    </th>
</tr>
<c:forEach var="event" items="${dataBean.getApsEvents(statusFilter.value)}" varStatus="status">

事件
预定
到期日
地位
${filter}
如您所见,状态列中添加了一个下拉列表,用于过滤显示的值 在标题下方的行中。该下拉列表显示的值与指定值相同

但是,我已经在getApsEvents(filter)方法中添加了一条日志记录行,以输出所需的值 发送到方法,且值始终为空字符串

我需要做哪些更改,以便用户可以选择一个选项,并传递该选项 作为bean上getApsEvents(filter)方法的参数,因此循环仅包含 我感兴趣的那些行

如果用户重新加载页面,则应记住所选的过滤器;如果用户选择其他选项,则应更改所选过滤器。但我们不需要记住,如果他们离开页面,然后就来了
稍后返回页面,然后它应该默认返回到“全部”。

好的,为了解决这个问题,我做了以下操作

一,。在我的数据bean上,我添加了一个statusFilter属性,带有getter和setter

二,。我将JSP文件更改为以下内容(在表单中选择):


事件
预定
到期日
地位
${filter}
这增加了下拉列表,并允许我重新提交表单,从而在数据bean上设置参数。在forEach循环中使用的数据bean上的标准getter会相应地过滤返回的列表

<table width="100%" cellpadding="3">
<tr style="vertical-align:center;">
    <th>
        Event
    </th>
    <th>
        Scheduled
    </th>
    <th>
        Due Date
    </th>
    <th>
        Status&nbsp;
        <form action="/thePage.html" method="POST">
            <select name="statusFilter">
                <c:forEach var="filter" items="${dataBean.getStatusFilters()}">
                    <option value="${filter}" <c:if test="${filter == dataBean.statusFilter}">selected="selected"</c:if>>${filter}</option>
                </c:forEach>
            </select>
            <input type="submit" value="Submit"/>
        </form>
    </th>
</tr>
<c:forEach var="event" items="${dataBean.apsEvents}" varStatus="status">