JSP获取参数问题
我有一个表单,如果计时器到达,表单会自动重定向到Servlet来更新数据库。我现在的问题是,如果javascript将窗口重定向到servlet,那么我的request.getParameter为nullJSP获取参数问题,jsp,servlets,parameters,request,Jsp,Servlets,Parameters,Request,我有一个表单,如果计时器到达,表单会自动重定向到Servlet来更新数据库。我现在的问题是,如果javascript将窗口重定向到servlet,那么我的request.getParameter为null function verify(f,whichCase){ if(whichCase == "Submit"){ msg = "Are you sure that you want to submit this test?"; var i = confirm(msg)
function verify(f,whichCase){
if(whichCase == "Submit"){
msg = "Are you sure that you want to submit this test?";
var i = confirm(msg)
if(i){
parent.window.location = "sindex.jsp"
}
return i;
}
}
我这样做是因为我的jsp中有一个iframe。计时器更新问题必须使用iframe。所以,当时间到或用户单击submit parent.window.location时,可以让我刷新父窗口
<form method="POST" action="${pageContext.request.contextPath}/TestServlet" onSubmit="return verify(this,whichPressed)">
下面是time up重定向到TestServlet触发doGet方法时的计时器
if((mins == 0) && (secs == 0)) {
window.alert("Time is up. Press OK to submit the test."); // change timeout message as required
var sUrl = "TestServlet";
parent.window.location = sUrl // redirects to specified page once timer ends and ok button is pressed
} else {
cd = setTimeout("redo()",1000);
}
我不确定我是否理解这个问题,但我认为你的问题在这里:
if((mins == 0) && (secs == 0)) {
window.alert("Time is up. Press OK to submit the test."); // change timeout message as required
var sUrl = "TestServlet";
parent.window.location = sUrl // redirects to specified page once timer ends and ok button is pressed
} else {
cd = setTimeout("redo()",1000);
}
您正在重定向到TestServlet,但没有发送任何参数,因为您没有提交表单。试着这样做:
if((mins == 0) && (secs == 0)) {
window.alert("Time is up. Press OK to submit the test."); // change timeout message as required
var sUrl = "TestServlet";
//myform it's a variable pointing to your form
myform.submit();
} else {
cd = setTimeout("redo()",1000);
}
希望这有帮助 您好,因为该表单位于iframe中
if((mins == 0) && (secs == 0)) {
window.alert("Time is up. Press OK to submit the test."); // change timeout message as required
var sUrl = "TestServlet";
//myform it's a variable pointing to your form
myform.submit();
} else {
cd = setTimeout("redo()",1000);
}