This content has been marked as final. Show 1 reply
it possible to get data directly from request object in service method of servletThe 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 methodBecause 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 objectBecause 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.