0

I'm currently working in a payment gateway kind of project. If any validation errors occurred in the back end, first I want to show the error message on my jsp page (Payment gateway's) and after 10seconds I want to dispatch the object(error code) to the merchant (merchant's web page) from my jsp page.

Currently, when I try to dispatch and forward in my jsp page, my error message/View content is not shown in the jsp. Instead of showing my error messages, it's just waiting for 10 seconds and forward the object to the merchant. Because I hope I'm not letting to commit request/response object in my jsp by doing the dispatching . Correct me if I'm wrong.

Please suggest me a good way to handle this situation?

I'm trying to do like this in my jsp page..

</head>
<body>
<form:form method="post"  commandName="item">
 <form:errors path="*" cssClass="errorblock" element="div" />
 
 <tr>
<td>Response Code :</td><td>${item.responseCode}</td>

<%="test" %>
</tr>
<%
Thread.sleep(10000); // sleep 10 seconds
RequestDispatcher rd = request.getRequestDispatcher("/merchant.jsp");
 //rd.include(request, response);
rd.forward(request, response);
%>
</body>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Janahan
  • 401
  • 8
  • 20

1 Answers1

2

You can't send output to the jsp and then sleep the thread or something, the webserver doesn't send the output until the code is finished executing, since we can't see your code, i'm going to assume you're attempting to output the error, sleep the thread, and then send a redirect, all that will do is write it out and then immediatley send a redirect when it's sent to the client.

Your best bet would likely be using javascript to send a redirect on the page you're redirecting clients to for displaying the error.

Edit: since comment formatting is weird: The servlet wasn't going to wait 10 seconds and then send the redirect, because all processing is done before the response is sent, the only way to send more data after the fact would be javascript, or some other strange black magic, the simplest and most elegant solution would be this:

<script type="text/javascript">
    window.location.replace("http://yourwebsite.com/merchant.jsp"); 
</script>
Zachary Craig
  • 2,192
  • 4
  • 23
  • 34
  • You're doing exactly what i thought you were. you're telling the interpreter to sleep 10 seconds, then forward the client, however the webserver finishes executing ALL code in the page before sending the output to the client, so there is no delay, the delay just makes the page take 10 seconds to load According to [this](http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery-javascript) something like this should work `` Edit: formatting in comments is weird. – Zachary Craig Oct 09 '14 at 01:37
  • Great.Thanks. Can able to sort it out through location.replace() and form submission using javascript – Janahan Oct 09 '14 at 03:14