This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi , 1. I have seen several methods return objects of interface types. e.g. getHeaderNames() returns an object of Enumeration type. How is such an object created in the implementation of the setHeaderNames() method by the servlet container? Enumeration, as we know, is an interface not a class? 2. How can we send a header request to a servlet? I guess we can only send Get and Post requests through HTML? How about Head, Put and Delete? Then what's the use of doXXX methods with Head, Put and Delete? Thanks in advance.
Dear Dinesh, 1. Container always implement interfaces like Enumeration, HttpServletrequest, HttpServletResponse in the classes whose names r not concerned to us. B'coz our interface can point(refer) to the object of those un-named classes. This is same, how container call doGet() method of servlet while passing an object of type HttpServletRequest and HttpServletResponse. e.g. HttpServletRequest req=new UnNamedClass(); => Here, UnNamedClass has implement that HttpServletRequest interface. 2. Yr form tag in html has Action parameter along with Method parameter. Where action will provide URL to identify the resource uniquely whereas at method u keep "HEAD". <form name="f1" action="/helloWorld.html" method="HEAD"> What happed here is, HEAD method will just receive Header values not the whole html page. "HEAD" method would be most useful in Web page Caching. Where u just check for Header, Last-Modified If it is the same as Cached page then Client browser will not make GET/POST request to srvr.This will atlast reduce the network traffic. Hope, i m clear enough. Best Regards, Dharmin
SCJP2 (93%),SCWCD(88%)<br />-------------------------------<br />Never under estimate yr self, just represent yr profile in proper manner.
2. How can we send a header request to a servlet? I guess we can only send Get and Post requests through HTML? How about Head, Put and Delete?
No, they are all valid HTTP methods. HTTP/1.1 (RFC2616) supports OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE and CONNECT methods. HttpServlet provides corresponding Java methods for all of them except CONNECT, which is used in tunneling applications and not really relevant for servlets. See the HttpServlet javadoc for information about what the default implementations for each of these do. - Peter [ January 13, 2003: Message edited by: Peter den Haan ]