我有一个 HTML 表单如下:-
<form name="login" id="login" action="<%=application.getContextPath()%>/GoogleLogin" method="get">
<input type=hidden id="firstName"/>
</form>
我在 javascript 中设置这个隐藏输入类型的值,并将表单提交给 servlet,如下所示:-
<script>
document.getElementById("firstName").value="XYZ";
document.getElementById("login").submit();
<script>
我的表单正在提交,但我无法获取请求参数“firstName”。
http://localhost:8080/Login/GoogleLogin?
感谢您的时间和考虑。
最佳答案
在输入字段中添加一个name
属性-
<input type="hidden" id="firstName" name="firstName" />
然后您将能够使用firstName
获取请求参数。
关于javascript - 无法通过javascript在表单提交时将参数发送到servlet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22245511/