Results 1 to 4 of 4

Thread: Need to obtain Absolute Filesystem path in Spring Controller

  1. #1
    Join Date
    Oct 2005
    Posts
    4

    Default Need to obtain Absolute Filesystem path in Spring Controller

    Hello,

    I am performing an XSLT transformation inside a org.springframework.web.servlet.mvc.Controller class and I've discovered that the controller views the relative root as my drive root, not my webapp's root, and therefore my transformer class is having trouble finding the xslt file that is in my webapp.

    How can I obtain the absolute filesystem path to my webapp from within a spring Controller? In the pure servlet world, you can do this by obtaining the ServletContext and doing a getRealPath() invocation. But since I'm inside a controller, (specifically the handleRequest() method) I don't have access to the ServletContext.

    Help! How can this be done?

  2. #2
    Join Date
    Jul 2005
    Posts
    246

    Default

    Quote Originally Posted by brado77
    But since I'm inside a controller, (specifically the handleRequest() method) I don't have access to the ServletContext.
    Yes you do. What's wrong with this?

    Code:
    request.getSession().getServletContext();
    Bob

  3. #3
    Join Date
    Oct 2005
    Posts
    4

    Default

    My brain....that's the problem. :-)

    Thanks, my brain shorted out....

    B

  4. #4
    Join Date
    Aug 2004
    Location
    Hawaii, US
    Posts
    225

    Default

    TMTOWTDI, you can also implement ServletContextAware in your controllers, for example. Of course, that only works inside a WebApplicationContext.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •