File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Servlet Response Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Response Object" Watch "Servlet Response Object" New topic

Servlet Response Object

renu richard
Ranch Hand

Joined: Oct 06, 2008
Posts: 116

I am calling a servlet (by hitting an URL from my application. The servlet will be returning the response object and the application which calls it is expecting an xml object so while sending the response i am setting the respose object as ...

But in few cases (some other application) which is also calling the same URL, expects the object returned in some cutom object. How can i set the response object for those cases.

For Example : application is expecting the response object in SampleClass object. [SampleClass is a class written by myself]......
In that case how can i set the response object...

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33106

What file type is it. A .class file. That would be a binary file.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Eduardo Bueno
Ranch Hand

Joined: Jun 04, 2009
Posts: 155
What is there in that class that can be executed? You can't simply try to forward to a java object.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
If this was my problem I would look into using Jersey - the open source REST style engine.

It is easy to configure Jersey classes to look at the HTTP request headers for the expected content type and return it.

This of course requires that you have control over the way your applications create requests and can set the appropriate header.

Servlets dont "return response object" they return a response stream - the headers in this stream must conform to HTTP standards but the body can be just about anything - XML, serialized Java object, image, whatever.

I agree. Here's the link:
subject: Servlet Response Object
It's not a secret anymore!