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?
JSP Interview Questions and Answers
(Continued from previous question...)
29. 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?
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-byreference" 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 ejb's 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.
(Continued on next question...)
Other Interview Questions
- What is a JSP and what is it used for?
- What is difference between custom JSP tags and beans?
- What are the two kinds of comments in JSP and what's the difference between them.
- What is JSP technology?
- What is JSP page?
- What are the implicit objects?
- How many JSP scripting elements and what are they?
- Why are JSP pages the preferred API for creating a web-based client program?
- Is JSP technology extensible?
- Can we use the constructor, instead of init(), to initialize servlet?
- How can a servlet refresh automatically if some new data has entered the database?
- The code in a finally clause will never fail to execute, right?
- How many messaging models do JMS provide for and what are they?
- What information is needed to create a TCP Socket?
- What Class.forName will do while loading drivers?
- How to Retrieve Warnings?
- How many JSP scripting elements are there and what are they?
- In the Servlet 2.4 specification SingleThreadModel has been deprecated, why?
- What are stored procedures? How is it useful?
- How do I include static files within a JSP page?
- Why does JComponent have add() and remove() methods but Component does not?
- How can I enable session tracking for JSP pages if the browser has disabled cookies?
- How do I prevent the output of my JSP or Servlet pages from being cached by the browser?
- How do you restrict page errors display in the JSP page?
- What JSP lifecycle methods can I override?
- How do I perform browser redirection from a JSP page?
- How does JSP handle run-time exceptions?
- How do I use comments within a JSP page?
- 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?
- How can I implement a thread-safe JSP page?
- How can I declare methods within my JSP page?
- Can I stop JSP execution while in the midst of processing a request?
- Can a JSP page process HTML FORM data?
- Is there a way to reference the "this" variable within a JSP page?
- How do you pass control from one JSP page to another?
- Is there a way I can set the inactivity lease period on a per-session basis?
- How does a servlet communicate with a JSP page?
- How do I include static files within a JSP page?
- Can you make use of a ServletOutputStream object from within a JSP page?
- Can a JSP page instantiate a serialized bean?
- What is JSP?
- How do I mix JSP and SSI #include?
- How do I mix JSP and SSI #include? What is the difference between include directive & jsp:include action?
- How do you prevent the Creation of a Session in a JSP Page and why? What is the difference between include directive & jsp:include action?
- How do I use a scriptlet to initialize a newly instantiated bean?
- How can I set a cookie and delete a cookie from within a JSP page?
- How do you connect to the database from JSP?
- What is the page directive is used to prevent a JSP page from automatically creating a session?
- How do you delete a Cookie within a JSP?
- Can we implement an interface in a JSP?
- What is the difference between ServletContext and PageContext?
- What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()?
- How to pass information from JSP to included JSP?
- How is JSP include directive different from JSP include action.
- Can we override the jspInit(), _jspService() and jspDestroy() methods?
- Why is _jspService() method starting with an '_' while other life cycle methods do not?
- Explain the life cycle of JSP?
- What happens when a page is statically included in another JSP page?
- A JSP page, include.jsp, has a instance variable "int a", now this page is statically included in another JSP page, index.jsp, which has a instance variable "int a" declared. What happens when the index.jsp page is requested by the client?
- Can you override jspInit() method? If yes, In which cases?
- What is the difference between directive include and jsp include?
- What is the difference between RequestDispatcher and sendRedirect?
- How does JSP handle runtime exceptions?
- How can my application get to know when a HttpSession is removed?
|