Issue
in my code i want to display alert message, that is coded in the servlet page. and then i want to redirect to jsp. i got alert message. but it doesn't redirect. Please check my code?
catch (Exception e) {
e.printStackTrace();
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String someMessage = "Vehicle already Assigned";
out.println("<html><head>");
out.println("<script type='text/javascript'>");
out.println("alert(" + "'" + someMessage + "'" + ");</script>");
out.println("</head><body></body></html>");
}
Where i put this line
getServletContext().getRequestDispatcher("VehicleSchedule.jsp").forward(request, response);
Solution
You can use something like this but i am not really recomend!
out.println("<script type=\"text/javascript\">");
out.println("alert('YOUR MESSAGE');");
out.println("window.location.href = \"YourPage.jsp\";");
out.println("</script>");
This is a tricky and easy way to do this! But you can do this with session
also if you want.
Answered By - Fotis Grigorakis
Answer Checked By - Willingham (JavaFixing Volunteer)