1 Reply Latest reply on Oct 19, 2008 7:20 PM by 843844

    obtaining root directory of web application

      Hi all.

      I am beginer in web application developing. You probably know how it is. Problem after problem:)

      So I started developing in JSF using NetBeans 6.0 with Tomcat 6.0.14 and i have the folowing problem:

      How can I programically get the root directory of my web application? I need it because I use some kind of filter, which redirects to error page, when unauthorized user tries to access protected resources. This error page is in root directory of my web application and has commandLink to logging site (action is set for method, which returns some string and navigation is defined for this string in facesconfig.xml), which is also in root directory. When I want to access for example /restricted/user/userPage.jsp and I am not logged in, the error page is displayed, but command link does not work. I supose the is a problem in current directory which is probably set for /restricted/user/.

      Thank You for any clues.


      Jahn Gurda
        • 1. Re: obtaining root directory of web application

          I am also new to web applications and JSF. But I can tell you that its a little hard to programically achieve the security you want to achieve i.e. displaying some error page if the user is not logged in, however you can do it relatively easily using web.xml or sun-web.xml files by defining some roles, filters etc.

          I read that somewhere, try searching on Google...I have not implemented that myself.

          As far as obtaning the root directory of web application is concerned you may try following in your button_action method or any where in Page Bean class:
          ServletContext theApplicationsServletContext = (ServletContext) this.getExternalContext().getContext();
          String rootPath = theApplicationsServletContext.getRealPath("/");
          Then use "rootPath" where ever you want, it contains the path of the root directory.
          It atleast works for me.....

          Its strange that no one has answered this query for so long. Hope someone does early, I also want the clear answer.


          Edited by: T.B.M on Oct 20, 2008 12:45 AM