I have a html form in jsp page which on submit is going to servlet ..After executing the functions in servlet i am again redirecting it to the same jsp page from which it has been invoked with a success message to display now on the same jsp page but i don't know how to do this ...
Here is my jsp form code..
<form action="CallTimer" method="GET">
<label class="button2">Set Date: </label>
<input type="text" name="date" id="date">
<label class="button2">Set Hour </label>
<input type="text" name="hour" id="hour">
<label class="button2">Set Minute: </label>
<input type="text" name="minute" id="minute">
<input type="Submit" name="Submit" value="Submit" id="Submit">
<br/><br/>
<label class="button2">Set File-Path: </label>
<input type="text" name="filepath" id="filepath">
</form>
And here is my servlet redirect code.
response.sendRedirect("Automail.jsp");
To create a JSP error page, we need to set page directive attribute isErrorPage value to true, then we can access exception jsp implicit object in the JSP and use it to send customized error message to the client.
A Servlet can communicate with JSP by using the RequestDispatcher mechanism. RequestDispatching is the process hand overing the request to another web component,and this component takes the response of generating the response.
The page redirect is used to move the redirect response to another resource of the web page. Basically we can call the redirect pages using sendRedirect() method in the jsp on client-side request can be used within the server or outside of the server.
At Servlet:
// You need to set value in session for redirection.
session.setAttribute("msg","Success");
response.sendRedirect("Automail.jsp");
At Automail.jsp
${msg}
In servlet:
response.sendRedirect("Automail.jsp?success=1");
In your jsp:
<c:if test="${param.success eq 1}">
<div> success </div>
</c:if>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With