简体   繁体   中英

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

<%
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 ; 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;
}
%>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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