Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show success message on page.redirect from servlet to jsp

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">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <label class="button2">Set Hour </label>
    <input type="text" name="hour" id="hour">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <label class="button2">Set Minute: </label>
    <input type="text" name="minute" id="minute">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <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");
like image 996
Adi Avatar asked Nov 14 '13 07:11

Adi


People also ask

How do I display error messages in the same JSP page?

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.

How does a servlet communicate with a JSP page?

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.

How can I redirect one page to another page in JSP?

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.


2 Answers

At Servlet:

 // You need to set value in session for redirection.
 session.setAttribute("msg","Success");

 response.sendRedirect("Automail.jsp");

At Automail.jsp

  ${msg}
like image 119
Masudul Avatar answered Nov 03 '22 11:11

Masudul


In servlet:

response.sendRedirect("Automail.jsp?success=1");

In your jsp:

<c:if test="${param.success eq 1}">
     <div> success </div>
</c:if>
like image 24
Kerb Avatar answered Nov 03 '22 12:11

Kerb