Are You Recruiter/Hiring Manager

*Filter candidates using TestYourCandidate.com and save 80% time ( saving time for recruiters and interviewers)
*More than 50% candidates can be filtered on Candidate Screening online tests
*Inbuilt exams are available in library, created and tested by experts Try Today...

Q. What is the difference between the getRequestDispatcher(String) and getNamedDispatcher(String) methods in the ServletContext Class? view answer

Q: What is the difference between Difference between doGet() and doPost()?
view answer

Q. What is the difference between ServletContext and ServletConfig?
view answer

Q: What is the difference between HttpServlet and GenericServlet?
view answer

Q.What is the difference between the getRequestDispatcher(String path) method of ServletRequest interface and ServletContext interface?
view answer

!!! Servlet interview questions !!!

Q.Difference forward() and response.sendRedirect() .

difference between the two is that sendRedirect always sends a header back to the client/browser. this header then contains the resource(page/servlet) which u wanted to be redirected. the browser uses this header to make another fresh request. thus sendRedirect has a overhead as to the extra remort trip being incurred. its like any other Http request being generated by ur browser. the advantage is that u can point to any resource(whether on the same domain or some other domain). for eg if sendRedirect was called at www.mydomain.com then it can also be used to redirect a call to a resource on www.techfaq360.com.

where as in case of forward() call, the above is not true. resources from the server, where the fwd. call was made, can only be requested for. but the major diff between the two is that forward just routes the request to the new resources which u specify in ur forward call. that means this route is made by the servlet engine at the server level only. no headers r sent to the browser which makes this very eficient. also the request and response objects remain the same both from where the forward call was made and the resource which was called.

In case of forward you can get the data from request object but in case of sendRedirect() you can get from session object, request object is not avilable.