2014-10-16 121 views
0

我有一个表格,在我的操作方法下拉列表在JSP页面中发送请求参数的jsp

<html:form action="/accountProcess"> 
     <html:hidden property="dispatch" value="getUsers" /> 
      <select name="user_status_filter" onchange="this.form.submit()"> 
      <option value="Status">Status</option> 
      <option value="all" >All</option> 
      <option value="inactive">Inactive</option> 
      <option value="active">Active</option> 
      </select> 
</html:form> 

我做了以下内容:

String requestValue = RequestUtils.getStringParameter(request, "user_status_filter"); 

和它工作的很好,但我也想发回相同的确切字符串,以便我可以将“选定”字符串添加到右边的选项元素,以便在提交表单时保持它被选中。

现在我在我的操作方法

request.setAttribute("selectedValue", requestValue); 

这样做,但我不知道如何有条件的逻辑添加到我的JSP,以便它像

if (${selectedValue}.equals("all") 
<option value="all" selected>All</option> 

回答

1

试试这个

<option value="all" ${selectedValue == 'all' ? 'selected' : ''}>All</option> 

只需在每个<option>中更改其比较值即可。

+0

谢谢你现在试试! – 2014-10-16 14:03:27

+0

它不工作...请问request.setAttribute和jsp之间有没有找到它? – 2014-10-16 14:06:18

+0

你正在做一个完整的帖子,对吧?不是AJAX请求? – 2014-10-16 14:07:14