|
INTERVIEW QUESTIONS
J2EE
JSP
DETAILS
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-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.
|
|
|
Category |
JSP Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.2) By 8794 users |
Added on |
9/16/2014 |
Views |
66255 |
Rate it! |
|
|
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-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. Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
How do I use comments within a JSP page?
|
View Answer
|
|
How does JSP handle run-time exceptions?
|
View Answer
|
|
How do I perform browser redirection from a JSP page?
|
View Answer
|
|
What JSP lifecycle methods can I override?
|
View Answer
|
|
How do you restrict page errors display in the JSP page?
|
View Answer
|
|
How do I prevent the output of my JSP or Servlet pages from being cached by the browser?
|
View Answer
|
|
Why does JComponent have add() and remove() methods but Component does not?
|
View Answer
|
|
How do I include static files within a JSP page?
|
View Answer
|
|
What are stored procedures? How is it useful?
|
View Answer
|
|
In the Servlet 2.4 specification SingleThreadModel has been deprecated, why?
|
View Answer
|
|
How many JSP scripting elements are there and what are they?
|
View Answer
|
|
How to Retrieve Warnings?
|
View Answer
|
|
What Class.forName will do while loading drivers?
|
View Answer
|
|
What information is needed to create a TCP Socket?
|
View Answer
|
|
How many messaging models do JMS provide for and what are they?
|
View Answer
|
|
The code in a finally clause will never fail to execute, right?
|
View Answer
|
|
How can a servlet refresh automatically if some new data has entered the database?
|
View Answer
|
|
Can we use the constructor, instead of init(), to initialize servlet?
|
View Answer
|
|
Is JSP technology extensible?
|
View Answer
|
|
Why are JSP pages the preferred API for creating a web-based client program?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All JSP Interview Questions & Answers - Exam Mode /
Learning Mode
|