1

I am new to servlets. My Q is if I use for response.sendredirect() which method gets called doGet or doPost()? I know that in jsp to servlet get or post method will get called according to method type. But if it is servlet to servlet request using response.sendRedirect() which method will get called? how servlet engine decides which method to call?

Thanks in avdance.

Sachin
  • 247
  • 4
  • 16
  • 26

3 Answers3

1

redirect is always use get method, redirection means a new request.. when we give send redirect actually happening is a new request from the user.. and it is always get.. since it is a new request we cant access the old request parameters

Lijo
  • 6,498
  • 5
  • 49
  • 60
0

response.sendRedirect is always a GET

Prateek
  • 12,014
  • 12
  • 60
  • 81
  • but how it decides? I think doGet() is the default one hence doGet will get called? Am I right? And what if doGet is not implemented? will it call doPost()? – Sachin Jan 21 '14 at 12:02
0

A sendRedirect() is always a 2 step process in which the server sends a URL Location and a status code of 301 to client browser. The client browser then GET's the URL and then goes to that url location.(You can see this url in the address bar).

Remember a request to a Http or a URL link is always a Get request whether the URL is to a servlet within application or to external location.

Refer http://docs.oracle.com/javaee/5/api/javax/servlet/http/HttpServletResponse.html#sendRedirect%28java.lang.String%29

Swapnil Sawant
  • 620
  • 8
  • 21