Programming Tutorials

Interview Question: Is it possible to share an HttpSession between a JSP and EJB? What happens when I change a value in the HttpSession from inside an EJB?

By: Ash in Interview Tutorials on 2008-08-13  

Question:Is it possible to share an HttpSession between a JSP and EJB? What happens when I change a value in the HttpSession from inside an EJB?

Answer:

You can pass the HttpSession as parameter to an EJB method, only if all objects in session are serializable. This has to be consider as passed-by-value, that means that it's read-only in the EJB. If anything is altered from inside the EJB, it won't be reflected back to the HttpSession of the Servlet Container. The pass-by-reference can be used between EJBs Remote Interfaces, as they are remote references.

While it is possible to pass an HttpSession as a parameter to an EJB object, it is considered to be bad practice in terms of object-oriented design. This is because you are creating an unnecessary coupling between back-end objects (EJBs) and front-end objects (HttpSession). Create a higher-level of abstraction for your EJBs API. Rather than passing the whole, fat, HttpSession (which carries with it a bunch of http semantics), create a class that acts as a value object (or structure) that holds all the data you need to pass back and forth between front-end/back-end.

Consider the case where your EJB needs to support a non HTTP-based client. This higher level of abstraction will be flexible enough to support it.

 

 

 

 





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Interview )

Tell me something about J2EE component?

Interview Question: Is there a particularly good IDE to use with Struts ?

What do you understand by a container in J2EE?

Interview Question: Is it possible to share an HttpSession between a JSP and EJB? What happens when I change a value in the HttpSession from inside an EJB?

Differentiate between .ear, .jar and .war files.

Interview Question: Do you have to credit Struts on your own website?

What are implicit Objects available to the JSP Page?

The output of System.out.println(5<<2) in Java

What is the difference between interface and abstract class?

Interview Question: What is the difference between sessioncontext and entitycontext?

Interview Question: Why are some of the class and element names counter-intuitive?

Why J2EE is suitable for the development of distributed multi-tiered enterprise applications?

What is the difference between Session Bean and Entity Bean?

Question: What is an output comment in JSP?

Interview Question: What is Deployment descriptor?

Latest Articles (in Interview)