Announcement Announcement Module
Collapse
No announcement yet.
best way to retrieve servlet container params? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

  • #2
    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?

    Comment


    • #3
      well,
      i'd rather not code to the servlet API...
      any other suggestions?

      Comment


      • #4
        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

        Comment


        • #5
          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.......

          Comment


          • #6
            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

            Comment


            • #7
              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.

              Comment

              Working...
              X