如何提交表格而不丢失已经在同一表格中选择的值 [英] how to submit a form without losing values already selected at the same form

查看:75
本文介绍了如何提交表格而不丢失已经在同一表格中选择的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有下拉列表的jstl.

I am using jstl with dropdown lists.

当我单击提交"按钮时,我成功完成了规范,但是int下拉列表的值被重新初始化.

When i click submit button i success the specification but values int dropdownlists are reinitialized.

所以我要提交表单而不丢失表单中已经选择的值,因为我需要始终保持表单中的同一级别.更清楚地说,用户从ddl中选择一个值,然后单击编辑"按钮以显示其他值选项,并以相同的形式填写它们,而不会丢失他选择的内容.

So I want to submit form without loosing the values already selected in the form because I need to stay always at the same level in the form.To be more clear, user choose a value from ddl and click edit button to show other options and fill them at the same form without loosing what he has selected.

我试图那样处理...

I have tried to deal like that...

<form action="myjsp.jsp" method="post">
<input type="Submit" value="Edit">

...但是它不起作用.

...but it doesn't work.

谢谢您的帮助.

推荐答案

您需要使用请求参数值预置输入.您可以通过${param.name}访问EL中的参数值.基本上:

You need to preset the inputs with the request parameter values. You can access parameter values in EL by ${param.name}. Basically:

<input type="text" name="foo" value="${param.foo}">

请注意,这对 XSS 敏感.您始终需要清理用户输入.您可以使用 JSTL函数为此的taglib.

Note that this is XSS sensitive. You always need to sanitize the user inputs. You can use the JSTL functions taglib for this.

<input type="text" name="foo" value="${fn:escapeXml(param.foo)}">

如果通过HTML <select>元素呈现下拉菜单,则会有些棘手.您需要设置所讨论的HTML <option>元素的selected属性.只要选项值与请求参数值匹配,就可以使用EL中的三元运算符打印selected属性.

In case of dropdowns rendered by HTML <select> element, it's a bit trickier. You need to set the selected attribute of the HTML <option> element in question. You can make use of the ternary operator in EL to print the selected attribute whenever the option value matches the request parameter value.

基本示例:

<select name="foo">
   <c:forEach items="${options}" var="option">
       <option ${param.foo == option ? 'selected' : ''}>${option}</option>
   </c:forEach>
</select>

这篇关于如何提交表格而不丢失已经在同一表格中选择的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆