简体   繁体   English

将请求参数从操作方法发送到jsp

[英]sending request parameter from action method to jsp

I have a form with a drop down list in a JSP page 我在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>

in my action method I'm doing the following: 在我的操作方法中,我正在执行以下操作:

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

and it's working great, but I also want to send back the same exact string so that I can add the "selected" string to the right option element to keep it selected when the form is submitted. 并且效果很好,但是我还想发送相同的字符串,以便可以在提交表单时将“ selected”字符串添加到正确的option元素中,以保持选中状态。

right now I'm doing this in my action method 现在我正在用我的动作方法

request.setAttribute("selectedValue", requestValue);

but I don't know how to add conditional logic to my jsp so that it's something like 但是我不知道如何在我的jsp中添加条件逻辑,所以它就像

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

Try this 尝试这个

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

Just change the value you compare it to in every <option> . 只需更改每个<option>与之比较的值即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM