Page1.JSP
//input text box
Enter Form id:<input type="text" name="formID" id="formID" >
<a href='Page2.jsp?formID=<%=request.getParameter("formID")%>' value="View Form" name="displayForm">Show Form</a>
这将返回空值。在第2页。 JSP
//get the input value
<%String formsubmitID=request.getParameter("formID");%>
这将返回 null。我无法解析。我尝试了使用 window.location
的所有方法,添加了一个添加 href
链接的按钮,但我无法访问输入文本字段并同时重定向两者。这是第一个 JSP 页面的代码,我需要从该页面重定向到另一个 JSP 页面,并在 Firest JSP 页面中输入输入文本字段。
我尝试使用按钮并在 Java 脚本中重定向
//javascript for redirecting to another page
function redirect(elem){
alert("in redirect Method:")
elem.setAttribute("action","Page2.jsp");
elem.submit();
return false;
}
// Page1.JSP
<form ACTION="Page2.jsp" METHOD="POST" onload='onload()'>
Enter Form id:<input type="text" name="formID" id="formID"/>
<INPUT TYPE="SUBMIT" value="Submit" onclick="redirect(this);">
</form>
这也行不通。当我使用 window.location.href
或 window.location
时,根本不会发生重定向。
请帮我找到同样的解决方案。
最佳答案
当您使用表单时,每当您单击按钮时,您都会被定向到 Page2.jsp(即表单操作中提到的 url),例如
<form ACTION="Page2.jsp">
Enter Form id:<input type="text" name="formID" id="formID"/>
<INPUT TYPE="SUBMIT" value="Submit">
</form>
在 Page2.jsp 中获取文本字段的值,例如
<%String formsubmitID=request.getParameter("formID");%>
关于javascript - 我正在尝试将一个 JSP 页面以及输入文本值重定向到另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42996037/