简体   繁体   English

在Java servlet doPost()方法中发送重定向

[英]send a redirection in java servlet doPost() method

I am able to get data from doPost() in java servlet and process the data accordingly. 我能够从java servlet中的doPost()获取数据并相应地处理数据。 After that, i need to send a redirection response which I am not clear about. 之后,我需要发送一个不清楚的重定向响应。 I intend to send the redirection page to an external php site.Anyone would share with me how could this be achieved? 我打算将重定向页面发送到外部php站点。任何人都会与我分享如何实现此目标? I have tried response.sendRedirection(URL); 我已经尝试过response.sendRedirection(URL); in doPost(), but it is not working and not redirect me to any new page. 在doPost()中,但是它不起作用并且无法将我重定向到任何新页面。

Thanks for reading. 谢谢阅读。

The method is response.sendRedirect() not response.sendRedirection(). 该方法是response.sendRedirect()而不是response.sendRedirection()。 That could be why you're getting the error. 这可能就是为什么您得到此错误。

You wrote response.sendRedirection(URL) . 您编写了response.sendRedirection(URL) The method is called response.sendRedirect(URL) . 该方法称为response.sendRedirect(URL)

Or do you write something in the output before invoking the response.sendRedirect()? 还是在调用response.sendRedirect()之前在输出中写一些东西? Im not sure how jsp handles this but, for example, in php you only can change the header before any actual output is sent. 我不确定jsp是如何处理的,但是例如,在php中,您只能在发送任何实际输出之前更改标头。

使用response.sendRedirect(url)代替response.sendRedirection(url)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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