Objects of HttpServletRequest and HttpServletResponse in Java?
servlets
Solution
Those are provided by the whatever Servlet Container your servlet is running in. This is a great example of how the Java world uses Interfaces to specify a contract that others follow by providing concrete implementations of those interfaces.
The Servlet Specification specifies the API for building the environment in which servlets execute, i.e. a servlet container. The servlet specification, as with any standard setting document, doesn't provide an actual software implementation, just the definiton of behaviors, aka the contract that implementing software must follow. Interfaces are used to define this behavior.
These interfaces are provided in the `javax.servlet.*` package space, part of the Java EE -- I think. Anyhow, it's part of Java. Folks who wish to provide a Servlet Container implementation must provide their classes that implement these interfaces; the internal details of specific implementations -- tomcat, jetty, etc. -- could vary wildly as long as they comply with the contract of the interface.
Many of the interfaces are implemented by the servlet container itself, but some are meant to be implemented by the application developer. For instance, if you are writing a webapp you will probably provide your own application specific implementations of the `javax.servlet.Servlet` interface.
At run time, when the servlet container receives a request that maps to your implementation of the Servlet interface, the container will create it's own implementation of the `javax.servlet.http.HttpServletRequest`, which represents the incoming request, and this will be passed to your Servlet so it can work whatever it wants to do with that request. Data available through the request object include request URI, request parameters, etc.
Problem
As HttpServletRequest And HttpServletResponse are Interfaces ,and we Know that in Java we cannot Instantiate Interfaces. Then How can we have objects of these 2 in doGet() or doPost()?? //something here ....... doPost(HttpServletRequest request,HttpServletResponse response){ //something here }