[英]request.getRequestDispatcher and response.sendRedirect don't work
Yes, I know that this is for sure duplicate question. 是的,我知道这肯定是重复的问题。 But... I have read all of answers for earlier asked questions, tried to fix everything... and my code still doesn't work.
但是...我已经阅读了较早提出的问题的所有答案,试图解决所有问题...但是我的代码仍然无法正常工作。
In index.jsp: 在index.jsp中:
<form action="/Login"method="post">
and 和
<input type="submit" value="LogIn">
In post method of servlet "/Login": 在servlet“ / Login”的post方法中:
if (result == 1) {
RequestDispatcher view=request.getRequestDispatcher(url);
view.forward(request, response);
} else {
response.sendRedirect("index.jsp");
return;
}
I was trying with: 我正在尝试:
"http://localhost:8080/home.jsp",
"/home.jsp",
"home.jsp"
response.sendRedirect
trying to do with and without "return;". 尝试做有和没有“返回”;
And nothing. 没事了。
This what I saw is only blank page and: If doPost()
method: url is "http://localhost:8080/Login"
. 我看到的只是空白页,并且:
If doPost()
方法:url为"http://localhost:8080/Login"
。 If doGet()
method: url is the same as abovementioned plus parameters input into a form. If doGet()
方法:url与上面提到的相同,并且将参数输入到表单中。
Could you help me? 你可以帮帮我吗?
If you want to redirect user to another page with a brand new request then using sendRedirect
function, but you must send redirect to the servlet
, servlet
will process and return to you a page. 如果您想使用全新的请求将用户重定向到另一个页面,请使用
sendRedirect
函数,但是您必须将重定向发送到servlet
, servlet
将处理并返回到您的页面。 You can not sendRedirect
directly to the jsp
page (you send redirect to a jsp page, it's like you right click on jsp page and run it on server). 您不能将
sendRedirect
直接发送到jsp
页面(将重定向发送到jsp页面,就像您右键单击jsp页面并在服务器上运行它)。 Please refer to this post to see the use of sendRedirect
method. 请参考这篇文章以查看
sendRedirect
方法的使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.