aspose file tools*
The moose likes JSP and the fly likes How to pass a non serializable object between jsp pages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to pass a non serializable object between jsp pages" Watch "How to pass a non serializable object between jsp pages" New topic
Author

How to pass a non serializable object between jsp pages

Sabari Unniramath
Greenhorn

Joined: Jul 10, 2004
Posts: 6
hi friends,

There are 4 jsp pages say, page1,page2,page3 and page4
I need to pass a non-serializable object between page1 and page4.
how can i achieve this ?

thanks for your help in advance,
sabari.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

How are you moving from one page to another?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Sabari Unniramath
Greenhorn

Joined: Jul 10, 2004
Posts: 6
First of all sorry for my rather unclear question.
I'm saving the class which contains a non serializable object (this object is a third party class) in the session and from the session any jsp can retrieve this object when no clustering is used. The issue comes when the application is deployed in a clustered environment because the class contains a non serializable object.
The error thrown is "Non Serializable Object Exists in the Session" . We are using weblogic server.
Can we do anything to make the application work in a clustered environment.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Make the object serializable.

Yes, I know this is analogous to the old "Doc, it hurts when I do this."/"Then don't do that." routine, but unless there are big reasons why the object isn't serializable, this is the easiest solution.

A way to get around this if you can't make the object serializable would be making all access to the object through some kind of remote interface - using RMI, EJBs, etc. - though this would probably be more "tricky" and resource intensive than just making the object serializable.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Travis Hein
Ranch Hand

Joined: Jun 06, 2006
Posts: 161
To share a Java object, that is not serializable, between JSP pages, when you can't make the object serializable, and can't put it on the session because the non serializable object breaks clustering.

I encountered something like this, with a vendor's proprietary Java API, which was really a poorly documented wrapper for their C API.

In my case, it as ok that the object did not live between requests on the same page, It was only needed to be passed between pages.

What we did was stuff it on the request attribute space, and forward to the second page. Forwarding between pages can then be done with struts, if you are using struts, or your own handler in the jsp code with request.getRequestDispatcher("page2.jsp").forward(request, response);


Error: Keyboard not attached. Press F1 to continue.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

A forward is not suitable when a form needs to be submitted, and certainly not in a 4-page scenario as described by the original post.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Travis Hein
Ranch Hand

Joined: Jun 06, 2006
Posts: 161
hmm, how about stuffing them into a servlet context attribute ?

I discovered while trying to solve a different issue, that servlet context attributes are not serialized across application reboots, or clusters, and are usually limited to the VM instance.

Though I am not sure if this behavior is consistent for different app servers, or if the app server is using a database to store serialized servlet context attributes.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to pass a non serializable object between jsp pages