HttpServletRequest, HttpServletResponse from EJB


EJB programming & troubleshooting: HttpServletRequest, HttpServletResponse from EJB

  1. is it possible to access HttpServletRequest, HttpServletResponse from EJB. if possible how to do that. if not then why.
  2. Since HttpServlet* are nothing to do with EJB, you can only "get access" to those objects, if they are passed in to an EJB method in some way (directly, via a session that is passed in or whatever).

    However, it is a better practice to decouple your web and ejb tiers, so hopefully you don't have a need for the request object. The EJB maybe needs some parameters, that in one case may come from HttpServletRequest, but that should all be handled at the web tier side of things.

    So, although you can pass them in, don't.
  3. Dion's advice is good. If you find yourself having to stick import javax.servlet... statments in your EJB's, then you going down the wrong path.

    If you have a bunch of parameters to pass in, you could create a DTO (Data Transfer Object) that is populated from the parameters in the request object. Have your web tier create one and then pass it to your EJB tier. You could also have a Swing client create one and pass it in as well. Otherwise your swing client (or any type of client) will have to implement HttpServletRequest in order to use your EJB's.