javascript 如何将javascript值分配给jsp页面中的jsp变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5715343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to assign javascript value to jsp variable in jsp page
提问by Anil Kumar
I have a text field, I need to send these text value to the same page which is in jsp .
我有一个文本字段,我需要将这些文本值发送到 jsp 中的同一页面。
I just want to assign javascript value to jsp variable.
我只想将 javascript 值分配给 jsp 变量。
回答by CloudyMarble
回答by BalusC
You could set a hidden field.
你可以设置一个隐藏字段。
Put this in your JSP form:
把它放在你的 JSP 表单中:
<input type="hidden" id="foo" name="foo" />
Execute this script whenever you want to fill the field:
每当您想填充该字段时,请执行此脚本:
document.getElementById("foo").value = "some value";
When you submit the form, it'll be available as follows in the servlet:
当您提交表单时,它将在 servlet 中如下可用:
String foo = request.getParameter("foo"); // "some value"
// ...