HttpServletResponse sendRedirect 永久
这将使用临时 302 HTTP 状态代码重定向请求:
HttpServletResponse response;
response.sendRedirect("http://somewhere");
但是是否可以使用永久 301 HTTP 状态代码重定向请求?
This will redirect a request with a temporary 302 HTTP status code:
HttpServletResponse response;
response.sendRedirect("http://somewhere");
But is it possible to redirect it with a permanent 301 HTTP status code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要手动设置响应状态和
Location
标头。在
sendRedirect()
之前设置状态将不起作用,因为sendRedirect()
会在之后将其覆盖为SC_FOUND
。You need to set the response status and the
Location
header manually.Setting the status before
sendRedirect()
won't work assendRedirect()
would overridde it toSC_FOUND
afterwards.我使用了以下代码,但对我不起作用。
然后我尝试了这段代码,它对我有用
,这对我有用,我遇到了同样的问题
如何在重定向时将状态设置为301
I used the following code, but didn't worked for me.
then I tried this piece of code it worked for me
this worked for me, I had the same issue
how to set status to 301 while redirecting