"K.V. Chandrinos" wrote:

> On Tue, 28 Dec 1999, Craig R. McClanahan wrote:
>
> > "Booth, Peter" wrote:
> >
> [...]
>
> > > I have seen examples of code where a servlet sets
> > > a respones error code:
> > >
> > > e.g.
> > > res.sendError(res.SC_INTERNAL_SERVER_ERROR);
> > >
> > > Is there any way that an applet can check for
> > > such an error code before reading from a URLConnection's
> > > input stream?
> > >
> >
> > In your applet, you can cast the URLConnection to an HttpURLConnection (since
> > you used an "http" URL to contact the servlet).  Now, you can call the
> > getResponseCode() method to retrieve the HTTP status code set by the servlet.
>
> I was thinking that (in theory, at least) one could issue a HEAD before
> deciding to issue a GET. Normally, the response for a HEAD would include
> error codes and save the tax that a GET might require. In that case, I was
> wondering:
>

That is essentially what your brower does to check if a page has changed, if you
set your properties to not check on every request.

>
> a) would anybody know how to issue a HEAD from URLConnection?

Cast the URLConnection to an HttpURLConnection after you create it.  Now you can
call setRequestMethod().

>

>
> b) is it MANDATORY for the servlet to implement the doHead() or some
> default implementation would suffice?
>

If your servlet extends HttpServlet the default implementation does it for you,
but in a somewhat crude manner -- it calls your doGet method and simply throws
away any content other than the headers.  You can override doHead() yourself if
you want to do it more efficiently than this.

>
> Am I missing something in the theory?
>
> TIA,
> Kostas
>

Craig

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to