This discussion is archived
1 Reply Latest reply: Dec 1, 2012 4:22 PM by EJP RSS

Servlet question........plz answer me

977411 Newbie
Currently Being Moderated
it possible to get data directly from request object in service method of servlet
than why it is not possible to write directly into response object through service method instead of this we have to take help of PrintWriter or ServletOutputStream class object
  • 1. Re: Servlet question........plz answer me
    EJP Guru
    Currently Being Moderated
    it possible to get data directly from request object in service method of servlet
    The request already exists and its headers have already been parsed before service() is called. But you can only get data from the request body if it consists of POST parameters, and that's because (a) they are formally equivalent to URL arguments and (b) are in a known format which is easily parsed.
    than why it is not possible to write directly into response object through service method
    Because the response doesn't exist yet: it is the purpose of the service() and other methods to create it.
    instead of this we have to take help of PrintWriter or ServletOutputStream class object
    Because that is the technique via which you create the response body. There is no standard format for it and no higher-level API provided.

    Please cut out the boldface in future. It isn't necessary and is hard to read.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points