473,372 Members | 858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

java.io.NotSerializableException:

madhoriya22
252 100+
Hi,
I am getting this exception while deploying my web application. It is occuring for the attributes which I have set for the session. Here is the method which sets the session attribues :----
Expand|Select|Wrap|Line Numbers
  1. protected void showIndexPage(HttpServletRequest request, HttpServletResponse response)
  2.     throws ServletException, IOException{
  3.  
  4.         PrintWriter out = response.getWriter();
  5.         HttpSession session = request.getSession(true);
  6.         response.setContentType("text/html;charset=UTF-8");
  7.         System.out.println("Inside showIndexPage() method");
  8.  
  9.         DAOFactory mysqlFactory = DAOFactory.getDAOFactory(DAOFactory.MYSQL);
  10.         System.out.println("below DAOFactory object------------->>");
  11.         OffshoreResourceDAO offshoreResourceDAO = mysqlFactory.getOffshoreResourceDAO();
  12.         Vector offshoreResourceVOList = offshoreResourceDAO.getResource();
  13.  
  14.         ClientResourceDAO clientResourceDAO = mysqlFactory.getClientResourceDAO();
  15.         Vector clientResourceVOList = clientResourceDAO.getClientResource();
  16.  
  17.         WorkPackageDetailsDAO workPackageDetailsDAO = mysqlFactory.getWorkPackageDetailsDAO();
  18.         Vector workPackageDetailsList = workPackageDetailsDAO.getWorkPackageDetails();
  19.         System.out.println("WorkPackageDetails are:"+workPackageDetailsList);
  20.  
  21.         Vector weekList = weekFinder();
  22.         System.out.println("Week List is:"+weekList);
  23.  
  24.         session.setAttribute("OffshoreResourceList",offshoreResourceVOList);
  25.         session.setAttribute("ClientResourceList", clientResourceVOList);
  26.         session.setAttribute("WorkPackageDetailsList", workPackageDetailsList);
  27.         session.setAttribute("WeekList", weekList);
  28.         request.getRequestDispatcher("index.jsp").forward(request,response);
  29.  
  30.         out.close();
  31.     }
  32.  
The attributes for which I am getting this exception are OffshoreResourceList,ClientResourceList,WorkPackag eDetailsList. All these are Vectors.While throwing exception, this warning is comin:---
Expand|Select|Wrap|Line Numbers
  1. WARNING: Cannot serialize session attribute OffshoreResourceList for session 5F8A4B888C40A6D0C72FB2B67A60A641
  2.  
How I can remove this exception.
Thanks and regards,
madhoriya
Jul 27 '07 #1
11 33552
JosAH
11,448 Expert 8TB
Make your OffshoreResourceList et al implement the Serializable interface. This
is extremely easy because that interface doesn't define any methods, so simply
do this:

Expand|Select|Wrap|Line Numbers
  1. public class OffshoreResourceList implements Serializable {
  2.    ...
  3. }
  4.  
Do the same for all the other classes that can't be serialized now.

kind regards,

Jos
Jul 27 '07 #2
madhoriya22
252 100+
Make your OffshoreResourceList et al implement the Serializable interface. This
is extremely easy because that interface doesn't define any methods, so simply
do this:

Expand|Select|Wrap|Line Numbers
  1. public class OffshoreResourceList implements Serializable {
  2.    ...
  3. }
  4.  
Do the same for all the other classes that can't be serialized now.

kind regards,

Jos
Hi Jos,
It's Ok. But I have read the Vector class documentation...It already implements the serializabe interface. Then why we have to serialize it again in this class

Thanks and regards,
madhoriya
Jul 27 '07 #3
JosAH
11,448 Expert 8TB
Hi Jos,
It's Ok. But I have read the Vector class documentation...It already implements the serializabe interface. Then why we have to serialize it again in this class

Thanks and regards,
madhoriya
Ah, ok, then the error diagnostic indicates that one of the members you've put
in that Vector doesn't implement the Serializable interface. I didn't know that
your class was a Vector itself.

kind regards,

Jos
Jul 27 '07 #4
madhoriya22
252 100+
Ah, ok, then the error diagnostic indicates that one of the members you've put
in that Vector doesn't implement the Serializable interface. I didn't know that
your class was a Vector itself.

kind regards,

Jos
Hi Jos,
Then what i have to do to remove this exception. See what I am putting in this vector is object of a Value Object class.... which is made of getters and setters methods.
These objects contains the values fetched from the database means every object has his ints, strings, double etc....

Thanks and regards,
madhoriya
Jul 27 '07 #5
JosAH
11,448 Expert 8TB
Hi Jos,
Then what i have to do to remove this exception. See what I am putting in this vector is object of a Value Object class.... which is made of getters and setters methods.
These objects contains the values fetched from the database means every object has his ints, strings, double etc....

Thanks and regards,
madhoriya
It's simple:

Expand|Select|Wrap|Line Numbers
  1. public class ValueObject implements Serializable {
  2.    ...
  3. }
  4.  
The ObjectInputStream and ObjectOutputStream explicitly check whether or not
a to be serialized object implements that interface; if not: *boink* they throw
that Exception.

So basically, an object (or a class) is Serializable if it implements the Serializable
interface itself and all of its members are Serializable too; primitives are always
Serializable.

kind regards,

Jos
Jul 27 '07 #6
madhoriya22
252 100+
It's simple:

Expand|Select|Wrap|Line Numbers
  1. public class ValueObject implements Serializable {
  2.    ...
  3. }
  4.  
The ObjectInputStream and ObjectOutputStream explicitly check whether or not
a to be serialized object implements that interface; if not: *boink* they throw
that Exception.

So basically, an object (or a class) is Serializable if it implements the Serializable
interface itself and all of its members are Serializable too; primitives are always
Serializable.

kind regards,

Jos
Hi Jos,
Got it !! Thanks ...

regards,
madhoriya
Jul 27 '07 #7
JosAH
11,448 Expert 8TB
Hi Jos,
Got it !! Thanks ...

regards,
madhoriya
You're welcome of course; does it work now?

kind regards,

Jos

ps. You could write a little article about it of course; put it in the Editor's Corner
where I take care of the typos so we can put it in the Java Articles section
afterwards. Just a concise article about Serialization not a (verbatim) copy of
the text in the API documentation ...<hint hint/>
Jul 27 '07 #8
madhoriya22
252 100+
You're welcome of course; does it work now?

kind regards,

Jos

ps. You could write a little article about it of course; put it in the Editor's Corner
where I take care of the typos so we can put it in the Java Articles section
afterwards. Just a concise article about Serialization not a (verbatim) copy of
the text in the API documentation ...<hint hint/>
Hi Jos,
Yep it worked. I vil think about your suggestion. Problem is work load.

Thanks and regards,
madhoriya
Jul 27 '07 #9
JosAH
11,448 Expert 8TB
Hi Jos,
Yep it worked. I vil think about your suggestion. Problem is work load.

Thanks and regards,
madhoriya
Take it easy; there's no pressure or time limit. Writing a good article under
pressure had never succeeded before.

kind regards,

Jos
Jul 27 '07 #10
madhoriya22
252 100+
Take it easy; there's no pressure or time limit. Writing a good article under
pressure had never succeeded before.

kind regards,

Jos
Hi Jos,
Again Thanks for ur suggestion.
I vil surely do it when i vill be free minded. I really want to do it

thanks and regards,
madhoriya
Jul 27 '07 #11
JosAH
11,448 Expert 8TB
Hi Jos,
Again Thanks for ur suggestion.
I vil surely do it when i vill be free minded. I really want to do it

thanks and regards,
madhoriya
Thanks for your good intentions; I appreciate it a lot; and realize: there's no
hurry and we both can take care of any hurdles if that are any. It can be a nice
article.

kind regards,

Jos
Jul 27 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Michael | last post by:
Hello I am trying to write a Java-Program which converts a XML-file in a HTML. It should take the Transformation-file from the XML-file itself. Below find a possible XML-file: <?xml...
0
by: Ravi Tallury | last post by:
Hi We are having issues with our application, certain portions of it stop responding while the rest of the application is fine. I am attaching the Java Core dump. If someone can let me know what...
1
by: ptaz | last post by:
Hi I'm trying to run a web page but I get the following error. Ca anyone please tell me a solution to this. Thanks Ptaz HTTP Status 500 - type Exception report
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
0
by: Markus Wollny | last post by:
Hello! When I try to run ./configure --with-java, it complains that ant doesn't work. However ant is installed, as is the latest Java SDK 1.4.2 from sun, PATH and JAVA_HOME are set correctly; ...
0
by: mailkhurana | last post by:
Hii , I am trying to use a type 2 driver to connect to DB2 0n AIX 5 I have a small java test to class to establish a conneciton with the db .. I am NOT using WAS or any appserver When I try to...
5
by: TZESENG | last post by:
DECEMBER 13, 2005 . Editions: N. America | Europe | Asia | Edition Preference News Analysis By Steve Hamm Source: http://www.businessweek.com/technology/content/dec2005/tc20051213_042973.htm...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
0
oll3i
by: oll3i | last post by:
package library.common; import java.sql.ResultSet; public interface LibraryInterface { public ResultSet getBookByAuthor(String author); public ResultSet getBookByName(String name);
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.