473,396 Members | 2,013 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,396 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 33555
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);
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.