Results 1 to 7 of 7

Thread: best way to retrieve servlet container params?

  1. #1

    Question best way to retrieve servlet container params?

    hi;
    i am looking for the best way to get servlet container's 'temp dir'.
    in the servlet API its read by using ctx.getAttribute("javax.servlet.context.tempdir")) ;
    i dont really want to write code to the servlet or spring api. i noticed that there are some related spring beans that i can work with but i did not understand if they are good for this or how their XML configuration looks like (i am reffering to ServletContextAttributeFactoryBean).

    anyu help would be great.
    thanks.
    __________
    Guy Katz
    www.xwave.co.il

  2. #2
    Join Date
    Jan 2006
    Location
    Wichita, KS
    Posts
    16

    Default WebUtils.getTempDir(ServletContext servletContext)

    There is the static getTempDir(ServletContext servletContext) method in org.springframework.web.util.WebUtils that returns a java.io.File. Maybe this will do?

  3. #3

    Default

    well,
    i'd rather not code to the servlet API...
    any other suggestions?
    __________
    Guy Katz
    www.xwave.co.il

  4. #4
    Join Date
    Jul 2005
    Posts
    246

    Default

    Quote Originally Posted by gkatz
    well,
    i'd rather not code to the servlet API...
    any other suggestions?
    You're running in a servlet container and you don't want to use the servlet API to discover the temp dir that only the servlet container knows about? Good luck with that. The only other way would be to use the servlet container's own API, but words can't describe how bad that would be.

    Bob

  5. #5

    Default

    why are you so surprised?
    i would rather not have spring (which i use in my business layer) know anything about the servlet container. even in my web layer (JSF based) i never use the servlet API (JSF abstracts the container - either servlet or portlet).

    anyway, i can allways encapsulate the access to the temp dir behind another class but i just wanted to know if spring has this ability built-in and i stumbled upon the ServletContextAttributeFactoryBean which looked interesting.......
    __________
    Guy Katz
    www.xwave.co.il

  6. #6
    Join Date
    Jul 2005
    Posts
    246

    Default

    Quote Originally Posted by gkatz
    why are you so surprised?
    i would rather not have spring (which i use in my business layer) know anything about the servlet container. even in my web layer (JSF based) i never use the servlet API (JSF abstracts the container - either servlet or portlet).

    anyway, i can allways encapsulate the access to the temp dir behind another class but i just wanted to know if spring has this ability built-in and i stumbled upon the ServletContextAttributeFactoryBean which looked interesting.......
    I'm not surprised at you wanting to do it - seems natural to me to reduce dependencies as much as possible.

    However, if you need access to a particular parameter of an API, don't be surprised if you can only get at that parameter through the API.

    Bob

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

    Default

    Quote Originally Posted by gkatz
    i'd rather not code to the servlet API...
    any other suggestions?
    One possible way is to use method injection, a fancy type of DI that spring supports. You can write a custom factory bean that *is* aware of the Servlet API, which can create temporary files. Then, use method injection as a way to transparently inject that temporary file into whatever bean you need it.

Posting Permissions

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