如何让JSP中提交后dropdownlist中的值不改变?
假设我有一个包含下拉列表的 jsp 页面。 当用户选择一个项目并单击“提交”将JSP页面提交给自己时, 之后,JSP 页面将重新加载,之前选择的项目将被取消选择。 我怎样才能使它即使在重新加载JSP页面后也不会改变?
Let's say i have a jsp page which contains a dropdownlist.
when user select a item and click submit to submit the JSP page to itself,
after that , the JSP page will reload and item selected before will disselected.
How can i make it not change even after reload the JSP page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你必须重新选择它。
所以它最终会像这样:
这样每次重新加载 jsp 页面时,您都会验证当前正在绘制的项目是否与用户之前选择的相同。 如果是这样,你将“selected”附加到选项中(第一次它不会匹配任何内容)
我在JSP中有点生疏,所以,可能有一种更“优雅”的方法来做到这一点,但是这个“旧的” -style”确实有效。
我希望它有帮助。
You have to re-select it.
So it will end up like this:
That way each time you reload the jsp page, you verify if the current item you're painting is the same it was previously selected by the user. If so, you append "selected" to the option ( the first time it won't match anything )
I'm a bit rusty in JSP, so , probably there is a more "elegant" way to do it, but this "old-style" does works for sure.
I hope it helps.
我认为这个方法更好:
我认为这个方法会起作用。
I think this method is better:
I think this method will work.
设置传入表单的
option
的selected
属性...您的输出应如下所示(假设用户选择“Saab”):Set the
selected
attribute of theoption
that was passed in to the form... your output should look like this (assuming the user selected "Saab"):