*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.Why don't we write a constructor in a servlet? view answer
Q.When we don't write any constructor for the servlet, how does container create an instance of servlet? view answer
Q.Why is it that we can't give relative URL's when using ServletContext.getRequestDispatcher() when we can use the same while calling ServletRequest.getRequestDispatcher()? view answer
Q.Once the destroy() method is called by the container, will the servlet be immediately destroyed? What happens to the tasks(threads) that the servlet might be executing at that time? view answer
Q.Request parameter How to find whether a parameter exists in the request object?
view answer
What is new in ServletRequest interface ? view answer
Q.Given the request path below, which are context path, servlet path and path info?
/bookstore/education/index.html view answer
Q.When a client request is sent to the servlet container, how does the container choose which servlet to invoke? view answer
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.