How to Show Alert in a Jsp from a Servlet and Then Redirect to Another Jsp

How to show alert in a jsp from a servlet and then redirect to another jsp?

You may possibly do this:

else
{
out.println("<script type=\"text/javascript\">");
out.println("alert('User or password incorrect');");
out.println("location='index.jsp';");
out.println("</script>");
}

Edited: 20th March 2018, 08:19 IST

OR without using js

else {
out.println("<meta http-equiv='refresh' content='3;URL=index.jsp'>");//redirects after 3 seconds
out.println("<p style='color:red;'>User or password incorrect!</p>");
}

How to redirect from servlet to jsp after getting alert?

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.

Alert inside a jsp page before redirect

you can try the redirection in javascript.

<script>
alert("Error");
window.location= "index.html";
</script>


Related Topics



Leave a reply



Submit