Redirecting a request using servlets and the “setHeader” method not working

后端 未结 4 781
情深已故
情深已故 2020-12-03 02:57

I am new to servlet development, and I was reading an ebook, and found that I can redirect to a different web page using

setHeader(\"Location\", \"http://ww         


        
4条回答
  •  死守一世寂寞
    2020-12-03 03:27

    As you can see, the response is still HTTP/1.1 200 OK. To indicate a redirect, you need to send back a 302 status code:

    response.setStatus(HttpServletResponse.SC_FOUND); // SC_FOUND = 302
    

提交回复
热议问题