I am new to EJB development. Please can any one explain how to access HttpRequest and HttpSession objects in Stateless, Stateful and Entitybeans?
Both HttpSession and HttpRequest are part of Servlet API. Conceptually Java Enterprise architecture expects that Servlet API usually used by Web-tier when EJB API is used by business tier. Therefore neither HttpSession nor HttpRequest not available inside EJB objects.
Actually there is no need to access Servlet API objects inside EJB in typical multi-tier application. However if you really need this - you can pass this objects as EJB methods input arguments
Whats your requirement?
In a distributed J2EE env, we have the model(EJB) and controller(Servlets) separated into multi-layers. Ideally we should pass/retreive any objects to/from both sides as serialized objects. So references like HttpRequest cannt be passed to server tier.
If you want to pass some session values to model layer, then in controller layer you should get them using HttpSession and HttpRequest,Serialize if not and pass them to the Model layer.
Even though you pass HTTPSession to EJB tier, you can only read the contents. If you change the contents of HttpSession, it wont reflect to the web-tier.