简体   繁体   中英

Request dispatching from one JSP to another JSP

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> 

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM