java 使用java检索隐藏的输入值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12171757/
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
Retrieving Hidden input value using java
提问by user1194310
I have a requirment. I have placed a Hidden field in my HTML. I want to retrieve that hidden text value from Java. Is there any way to do it? I know we can do it in javascript but i need to extract the value from java. I have created a hidden text field like this:
我有一个要求。我在 HTML 中放置了一个隐藏字段。我想从 Java 中检索隐藏的文本值。有什么办法吗?我知道我们可以在 javascript 中做到这一点,但我需要从 java 中提取值。我创建了一个像这样的隐藏文本字段:
<input type="HIDDEN" name="X" value="2356544">
I want to retrieve 2356544 through java. Please let me know how to do this.
我想通过java检索2356544。请让我知道如何做到这一点。
回答by Sal
If you are using Servlets you can retrive the value of a parameter with
如果您使用的是 Servlet,则可以使用以下命令检索参数的值
request.getParameter("X");
or if you have a JSP then use
或者如果你有一个 JSP 然后使用
Hello <c:out value="${param.X}" />
回答by Deepak
This has to be a web application since it is using html. So in a web application you have request object, so you can use
这必须是一个 Web 应用程序,因为它使用的是 html。因此,在 Web 应用程序中,您有请求对象,因此您可以使用
request.getParameter("X") from your servlet or action.
request.getParameter("X") 来自您的 servlet 或操作。
回答by Rejayi CS
try like this
像这样尝试
create id attribute in hidden field as id="X" then in javascript take value using id
在隐藏字段中创建 id 属性为 id="X" 然后在 javascript 中使用 id 取值
var value=document.getElementById('X').value;
or
或者
using name
使用名称
var value=document.getElementsByName('X').value;