This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
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.
Joined: Sep 21, 2005
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com