• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Why HttpServlet implements Serializable interface  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GenericServlet implements Serializable and HttpServlet extends GenericServelet then Serialization facility available to HttpServlet.. Then why HttpServlet implements Serializable interface?
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not?
It is probably more for documentation purposes than anything else - ie just so the javadoc will explicitly state it, rather than the reader having to KNOW that it extends a class that implements serializable.
 
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Serializable - The Breakfast Interface

Because Serializable is a marker interface, any class that is indeed serializable should include this interface in its class declaration.

I can create a class with all, boring Java data types and call it serializable. Then I can subclass it and add an instance variable that is of type DataSource or DatabaseConnection, which isn't declared as being transient, and isn't serializable. In this case, I have extended a class that IS serializable, but my own class is indeed NOT serializable.

Does that make any sense?

By the way, if you extended a Serializable class, but added instance variables that weren't Serializable, would you be a "serial killer?"


-Cameron
 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not satisfied with the above answers
There must be a decent reason to decide to set this class Serializable. Servlets are not supposed to hold states, so I can't understand either why it has to be Serializable. Any relation to distributed environments ?
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlets are allowed to hold state, they just shouldn't hold user state. I can think of better ways to do it, but a cluster may require Servlets to be Serializable.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!