This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I've a plain Java bean which I used as a model in the MVC architecture. My application is running in the remote server. In this situation whether my model should implement the Serializable Interface. If yes, what will be a error/exception if I failed to implement a Serializable interface?
How is your Java bean running on the remote server. That is, is it running in a Java EE container? Spring? The server documentation should tell you the rules of when and what to serialize. It also depends on how you use your Java Bean. Do you store references to it in the session or application object (if you run in a web container) or do you just create, use, and destroy it in a single function? A quick Google search found java.io.NotSerializableException.
Joined: Jun 09, 2010
Thanks for the reply.
My web application is running in one of the webservers. I just create a javaBean and set some values and put it in the request scope. In my JSP I just get the bean from the request scope and print the value... simple.
For this simple process whether my been need to implement the serializable interface. And what are all the risks involved if I didn't implement the Serializable interface. I heard that we need to implement serializable to avoid accessing/changing the data through the network. Is it true?
Thanks in advance.
Joined: Jun 01, 2010
I suggest learning more about your server architecture. You mentioned it runs on one of your web servers but a web server alone won't run your JSP. You need a JSP container to do that. Do you have a distributed environment in which it's possible to create your Java Bean on one server and have the JSP process on another server? Do your servers support fail-over? Yes, you must implement Serializable if your JavaBean is sent across the network or is saved to disk at any time.
Joined: Jun 09, 2010
Just tell me what are all the risks involved if my bean doesn't implement the Serializable interface?
Vijayakumar Rengaraj wrote:Just tell me what are all the risks involved if my bean doesn't implement the Serializable interface?
I do not care for the tone that you have taken with people who are volunteering their time to help you. I have closed this topic. Please feel free to open a new topic on this subject where you will have the opportunity to show the proper level of politeness and gratitude for any help that you will receive.