Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

How to pass a non serializable object between jsp pages

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
 
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic