开发者

How can I return a 302 HTTP response in JSP?

I need to submit a form using JavaScript. The problem is my JavaScript POST request gets an “OK — 200” respon开发者_StackOverflow社区se. In order to make it 302 I think I need to use response.sendredirect in my JavaScript JSP function. Can any body tell me how to use it? With example code.


You won’t use response.sendredirect in your JavaScript, there’s no such thing. If you’re submitting a form using JavaScript, then JavaScript is your HTTP client. It sends the POST request, with the form data, to whichever server you’re submitting to.

The server then sends the HTTP response back to your JavaScript. It’s currently sending 200, but you’re looking for it to return a 302 redirect instead. You’d use response.sendredirect on the server to do that — it’s not part of your JavaScript. There’s also no way to specify what sort of response you want in HTTP. It’s entirely up to the server.

So, judging by your tags, you’ll want to use response.sendredirect in your JSP code on the server. I’m afraid I’m not familiar with JSP, so I can’t really help there. It might help other answerers if you post some of your server-side code though — at the moment we’ve got no idea what’s going on there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜