Possible Duplicate:
URL redirection in Java return 302 instead of 301
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.sendRedirect(redirectUrl);
I use this in my redirectcontroller to give the redirect 301 as status. But when I check the header of the page in a header checker It gives a 302 (Moved Temporarily) as result.
Answer:
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.setHeader("Location", redirectUrl);
Yes, you’re calling
sendRedirectwhich is documented like this (emphasis mine):In other words, your first line is completely irrelevant when you explicitly call
sendRedirect. If you want to be explicit about it, you can set the status, set the appropriate header and then just let the response end normally.