简体   繁体   English

response.sendRedirect(“ / test.jsp”); 不起作用

[英]response.sendRedirect(“/test.jsp”); doesn't work

I'm working with jsp and I have two conditions for redirect to some page, this is my code 我正在使用jsp并且我有两个条件可以重定向到某些页面,这是我的代码

<%
if(traer.getFormapacretro().equals("RELACIONESLABORALES")&&tarea.getEstado()==4)
{
System.out.println("::::::::::::::::RELACIONES"+tarea.getEstado()+"LABORALES:::::::::::::::::::::");
response.sendRedirect("/html/controltareas/viewpacrl.jsp");
}
else if(traer.getFormapacretro().equals("CAPACITACION")&&tarea.getEstado()==4)
{
System.out.println("::::::::::::::::CAPACITACION"+tarea.getEstado()+":::::::::::::::::::::");
response.sendRedirect("/html/controltareas/viewpaccapacita.jsp");

}
%>

But when the form is loaded it only shows results on the console but not redirect to the page in the condition, some help? 但是,在加载表单时,它仅在控制台上显示结果,而在这种情况下不重定向到页面,有帮助吗?

You have to always use return ; 你必须总是用return ; when you are using 使用时

response.sendRedirect("");

Your code should look like this 您的代码应如下所示

<%
if(traer.getFormapacretro().equals("RELACIONESLABORALES")&&tarea.getEstado()==4)
{
System.out.println("::::::::::::::::RELACIONES"+tarea.getEstado()+"LABORALES:::::::::::::::::::::");
response.sendRedirect("/html/controltareas/viewpacrl.jsp");
return;
}
else if(traer.getFormapacretro().equals("CAPACITACION")&&tarea.getEstado()==4)
{
System.out.println("::::::::::::::::CAPACITACION"+tarea.getEstado()+":::::::::::::::::::::");
response.sendRedirect("/html/controltareas/viewpaccapacita.jsp");
return;
}
%>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM