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

I have an html form on a jsp page that on submit is submitted to a servlet. After executing the functions in the servlet, I redirect it again to the same jsp page from which it was called with the message that the same jsp page was launched successfully, but I do not 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 redirection code.

response.sendRedirect("Automail.jsp");
+4
source share
4 answers

According to your requirement, I suggest you switch to ajax.I gave a simple example of how to transfer data to a servlet. Click here to learn more about jquery ajax

$.ajax(
               {
                   type: "get",
                   url: "CallTimer", //Your full URL goes here
                   data: { name: name1, date: date1,hour:hour1,filepath:filepath1,minute:minute1},
                   success: function(data, textStatus, jqXHR){
                       alert("success");                  
                   },
                   error: function(jqXHR){
                       alert(jqXHR.responseStatus);
                   }
               });

note 1 , hour1. . get , URL-, 2048

+2

Servlet:

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

 response.sendRedirect("Automail.jsp");

Automail.jsp

  ${msg}
+6

To servlet:

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

In jsp:

<c:if test="${param.success eq 1}">
     <div> success </div>
</c:if>
+3
source

In the servlet:

session.setAttribute("message","successful");
response.sendRedirect("addLibrarian.jsp");

In JSP:

<c:if test="${not empty message}">
    <h3 style='color:green'>${message}</h3>
    <c:remove var="message"/>
</c:if>

Remember to delete the variable after printing so as not to include the message after refreshing the page.

0
source

All Articles