2
I made an Interceptor so that every time the system had a message to display trigger a javascript with the message.
public class MessagesInterceptor extends HandlerInterceptorAdapter {
public static final String urlBase = "http://localhost:8084";
public static String urlToRedirect = "";
public static String message = "";
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response,
Object handler, ModelAndView modelAndView)
throws Exception {
if(message.length() > 0){
PrintWriter pw = response.getWriter();
pw.write("<script>"
+ "window.alert('"+message+"'); "
+ "location.href='" + urlBase + urlToRedirect + "';"
+ "</script>");
pw.close();
message = "";
}
}
}
But my problem is which url
I’ll redirect.
I created a variable urlToRedirect
to tell which url
I’ll redirect.
I wish I didn’t have her and find out if there’s any way to get to where action
is redirecting without having to pass to a variable inside the Interceptor.
@RequestMapping(Routes.basicExercisesAct)
public String runExercise(HttpServletRequest request, Model model){
resolution = request.getParameter("resolution");
//javax.swing.JOptionPane.showMessageDialog(null, resolution);
exercise.buildGrading(resolution);
if (exercise.hasCompileErrors != true) {
//exercicio.salvarBancoDeDados(codigoUsuario, conexao);
if (chooser.canDoNextExercise() == true) {
MessagesInterceptor.urlToRedirect = Routes.basicExercisesNew;
return "redirect:"+Routes.basicExercisesNew;
} else {
//javax.swing.JOptionPane.showMessageDialog(null, "Parabéns. Você passou no teste!");
MessagesInterceptor.urlToRedirect = Routes.main;
return "redirect:"+Routes.main;
}
} else {
//exercicio.salvarBancoErroDeCompilacao(codigoUsuario, conexao);
if (exercise.endOfAttempts == true) {
if (chooser.canDoNextExercise() == true) {
/*javax.swing.JOptionPane.showMessageDialog(null, "Estouro de "
+ "quantidade de tentativas atingido. "
+ "Por favor, fazer o próximo exercício");
*/
MessagesInterceptor.urlToRedirect = Routes.basicExercisesNew;
return "redirect:"+Routes.basicExercisesNew;
} else {
//javax.swing.JOptionPane.showMessageDialog(null, "Você foi reprovado no teste");
MessagesInterceptor.urlToRedirect = Routes.main;
return "redirect:"+Routes.main;
}
}
else {
MessagesInterceptor.urlToRedirect = Routes.basicExercisesUpdate;
return "redirect:"+Routes.basicExercisesUpdate;
}
}
}
If the question is not clear, let me know.