0

I am posting data to servlet using jquery .post() method. The data is being posted and servlet is able to catch the data. But in my firebug I see 302 once the post request is done.

Also I am redirecting the user to success page in my servlet. But the redirect is not happening!!

Should'nt I be getting 200 on the post request?

And why is a simple response.sendRedirect("success.jsp") not happening?

enter image description here

When I click on the response tab I can see the success.jsp html tags.

Please throw light on what is happening? How do I correct it?

Emre Erkan
  • 8,433
  • 3
  • 48
  • 53
enthusiastic
  • 1,702
  • 4
  • 19
  • 31
  • possible duplicate of [How to manage a redirect request after a jQuery Ajax call](http://stackoverflow.com/questions/199099/how-to-manage-a-redirect-request-after-a-jquery-ajax-call) – Paul Dec 23 '11 at 07:29

2 Answers2

0

Your servlet is sending the redirect message, which gives you the 302 response header. It'd be better to send back an url, and redirect the user to it on success itself.

Like so:

$.post("scripturl", { data: data }, function(result) { 
    if (result.success) {
        window.location.href = result.url;
    }
})
Andreas Eriksson
  • 8,979
  • 8
  • 47
  • 65
0

That is not wierd. because you have called sendRedirect method in the server, server send back the response with 302 for informing the client browser to redirect to another url (which is also sent in the response header).

You can use forward method instead of redirect method if you want to do the redirection from the server side.

Manjula
  • 4,961
  • 3
  • 28
  • 41