Discussions

Web tier: servlets, JSP, Web frameworks: What is the equivalent of .getServletContext() in Struts?

  1. I am trying to setup an application XML config file that I want to place in the "WEB-INF" directory. I'm having trouble getting the server to see the file. If I were using a normal servlet, I'd use .getServletContext(). However, I don't think this is how Struts works.

    Any help would be appreciated.

    Thanks,
    Chris
  2. reply[ Go to top ]

    I thought the action in Struts is just an extention to the normal servlet and all methods you could get in servlet is available to the action.
  3. i assume you're trying to get a reference to the servlet context from within an action class? if so, you can use the protected instance variable of the Action superclass or the public getter, like so:

    servlet.getServletContext();

    or

    getServlet().getServletContext()
  4. Hi christopher
    The following must be a solution for Urs I think.
    Try Ur luck.

    public ActionForward execute(ActionMapping map, ActionForm form,HttpServletRequest req, HttpServletResponse resp) throws Exception {
    //***********************************
    req.getSession().getServletContext();
                    //***********************************

    Bye for now
    suriya