Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pass a non serializable object between jsp pages

 
Sabari Unniramath
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you moving from one page to another?
 
Sabari Unniramath
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Travis Hein
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Travis Hein
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic