• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can a Servlet return an object

 
Mike Yu
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is it possible for a servlet to return an object, so that other classes or jsp pages can use this object?
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Yu:
Hi,
Is it possible for a servlet to return an object, so that other classes or jsp pages can use this object?

Return it to where? Do you mean create an object and save it in the session? Or do you mean return it to the client and have the client send it back? If the former then it is no problem. If it is the latter then you need to have a Java app at the client.
 
Mike Yu
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Thomas,
Thank you for your reply.
By returning an object, I mean the behaviour like a method returning something in a regular class.
A futher question: in Servlet, if I have a object, for example,
Object obj=obj1;
mySession.addAtrribute("attr", obj);
Then later, if we get this obj from the session and alter it outside this servlet. Will this also change the obj inside the servlet?
Can you also give your opinion on my another question about HttpSession. http://www.coderanch.com/t/356038/Servlets/java/HttpSession
[ March 06, 2003: Message edited by: Mike Yu ]
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first part, I still don't get it. Return it to where?
The second part, the answer is yes. If the object is changed the change will be seen by the servlet.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!