• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Normally trees don't drive trucks. Does this tiny ad have a license?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic