aspose file tools*
The moose likes Beginning Java and the fly likes How to return an object to the user in the java server programming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to return an object to the user in the java server programming" Watch "How to return an object to the user in the java server programming" New topic
Author

How to return an object to the user in the java server programming

cake naiyou
Greenhorn

Joined: Apr 29, 2011
Posts: 27
I have a java servelet segment, which can generate a XML file and print it out on the screen.

The related code are giving as follows



Right now, I need to return this process object to the user, how should I do that? Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

I don't really understand the question. That code appears to do three things:

(1) It declares that the response will be HTML, encoded in UTF-8.

(2) It calls the "serialize" method of some object which presumably sends something to the response. Your comment says that "something" is an XML document.

(3) It calls the toString() method of that object and appends the result of that to the response.

Those are mutually contradictory -- XML isn't HTML, and it doesn't make sense to append text after an XML document -- but your question is that you want to return the object to the user.

That requirement is incomplete. You are going to have to return it in some format, since HTTP doesn't have a concept of "object". So, what format do you want?
cake naiyou
Greenhorn

Joined: Apr 29, 2011
Posts: 27
Paul Clapham,

I am also kind new to the whole implementation. Since I just was asked to add some minor feature on the top of it. The "process" itself is a class, "serialize" is a method for this class.



is used to generate this "process" object. Right now, I need to return this one to the client.

I hope I explain my question clearly.

Paul Clapham wrote:I don't really understand the question. That code appears to do three things:

(1) It declares that the response will be HTML, encoded in UTF-8.

(2) It calls the "serialize" method of some object which presumably sends something to the response. Your comment says that "something" is an XML document.

(3) It calls the toString() method of that object and appends the result of that to the response.

Those are mutually contradictory -- XML isn't HTML, and it doesn't make sense to append text after an XML document -- but your question is that you want to return the object to the user.

That requirement is incomplete. You are going to have to return it in some format, since HTTP doesn't have a concept of "object". So, what format do you want?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

cake naiyou wrote:Paul Clapham,

I am also kind new to the whole implementation. Since I just was asked to add some minor feature on the top of it. The "process" itself is a class, "serialize" is a method for this class.



is used to generate this "process" object. Right now, I need to return this one to the client.

I hope I explain my question clearly.


No, you didn't. I asked you what format you were supposed to return the object in. You didn't answer that. Quite likely you don't know what format to use; if so, then go back to whoever assigned you this problem and ask for more information.
cake naiyou
Greenhorn

Joined: Apr 29, 2011
Posts: 27

Hi Paul Clapham,
I heard that ObjectOutputStream can be used to transfer the object over the HTTP protocol. But I am having the new problem. I am implementing an applet ---servlet communication. There are two parameters that need to be sent by applet to the servlet. I am not sure can I implement the transferring process as follows? If not, how to handle the transferring processing involving multiple parameters?

Applet side:



Servlet side:


Paul Clapham wrote:
cake naiyou wrote:Paul Clapham,

I am also kind new to the whole implementation. Since I just was asked to add some minor feature on the top of it. The "process" itself is a class, "serialize" is a method for this class.



is used to generate this "process" object. Right now, I need to return this one to the client.

I hope I explain my question clearly.


No, you didn't. I asked you what format you were supposed to return the object in. You didn't answer that. Quite likely you don't know what format to use; if so, then go back to whoever assigned you this problem and ask for more information.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

Yes, you could certainly do that. Apart from the fact that your example shows objects being sent from the applet to the servlet, which is the opposite of what you said you wanted to do.

And you would only want to do that, if sending the objects to an applet was your actual requirement. But I believe I have already asked you twice what your actual requirement is, and had no response. I don't think there is any point in continuing this conversation.
 
 
subject: How to return an object to the user in the java server programming