[英]Why can't I access the value of the field in jsp (it returns null)?
我有以下javascript函数:
function confirmaEnviar()
{
document.getElementById("data").value =clave2.value;
alert(document.getElementById("data").value);
more code here
在我检查的地方,我可以分配一个新的值tu数据;
数据定义如下:
<form action="client.json" method="post" name="usuario" id="usuario">
more code here
<input type="hidden" name="data" id="data" value="prueba" />
more code here
</form>
稍后在jsp部分:
<div><a href="javascript:void();" onclick="
javascript:if(confirmaEnviar())$('#usuario').submit();
<%
<%
more code here
String str= request.getParameter("data");
str始终为null,您能指出我的能力吗?
谢谢。
我认为您已将属性action =“ client.json”更改为action =“ client.jsp”。
可能是页面无法获取请求参数。。我想。
在导致页面绘制的请求中,str变量将具有“数据”参数的值。 似乎第一次绘制页面时,请求中没有“ data”参数; 表单中有一个“数据”字段,将来会提交,但目前仍在。
“数据”请求参数唯一具有值的时间是在绘制页面之前提交表单的时间。
另外(这与您的问题无关),在您的JSP页面上包含Java代码也是一种不好的做法。 在Servlet或控制器中使用Java(如果使用Spring),并使用jsp页面进行查看。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.