int counter = 1; response.setContentType("text/html"); PrintWriter out = response.getWriter();
/* Server Information */ int lport = request.getLocalPort(); int rport = request.getRemotePort(); int sport = request.getServerPort(); ================================================================== I know that HttpServletRequest extends javax.servlet.ServletRequest interface and also that the methods in the ServletRequest interface are implemented by the class ServletRequestWrapper class. The piece which I am not able to figure out is how is the connection made by the parameter 'request' and the implementing class ServletRequestWrapper. Please advise.
The doPost method is passed an object that implements the HttpServletRequest interface as the "request" parameter. Which class is used for this is up to the servlet container. It may be a ServletRequestWrapper object, but that is not a requirement of the servlet spec - this class merely helps servlet container implementors, and they are free to come up with their own object that implements HttpServletRequest.
It's a similar situation for the web app developer with HttpServlet - that's a convenience class that can be used, but doesn't have to be used, as long as the servlet class implements all the required interfaces.
Does this answer your question?
Ping & DNS - updated with new look and Ping home screen widget
Joined: Sep 21, 2005
Why is that there is no explicit reference to the implementing class-in my understanding, it should have been 'ServletRequestWrapper'-within the code. In other words, there is no statement like 'ServletRequestWrapper' implements ServletRequest interface' within the code to make it work.
Or as you stated, is the web container designed to resolve the reference between the implementing class (ServletRequestWrapper) and the corresponding interface (HttpServletRequest) at runtime by working backwards from the parameter name (request) which is of type HttpServletRequest? Please advise.
The container has nothing to resolve. There is only one object, and inside of doGet all that matters is that it does indeed implement HttpServletRequest. In other places (internally in the container) it will treat it as the object it actually is, but that is off-limits to the servlet code.