This only works from inside a Tapestry page because this is linked to the servlet context which knows about the real path. To a standard class you need to pass the information somehow.
Without injection it can be: getPage().getRequestCycle().getRequestContext().getServlet().getServletContext().getRealPath(fileName); Len www.len.ro On Thu, 2006-12-21 at 11:38 +0100, Cyrille37 wrote: > Marilen Corciovei a écrit : > > Hello, > > > > @InjectObject("service:tapestry.globals.ServletContext") > > public abstract ServletContext getServletContext(); > > I could not use an abstract class. How will I instantiate it ? > I would not like to instantiate it with an IoC but like a normal Java > Object. > > Cyrille. > > > > ... > > String imageDir = getServletContext().getRealPath("images"); > > ... > > > > Len > > www.len.ro <http://www.len.ro> > > > > > > On Thu, 2006-12-21 at 10:02 +0100, Cyrille37 wrote: > >> Hello, > >> Sure it is a beginner question, but I'm a beginner :o) > >> > >> I would like to read a file which is located in the web root folder, and > >> put it in a String. > >> I had a look around the Internet and found some tricks : > >> > >> A la "Servlet" : > >> ServletContext theApplicationsServletContext = (ServletContext) > >> this.getExternalContext().getContext(); > >> String realPath = > >> theApplicationsServletContext.getRealPath("/resources/images"); > >> File file = new File(realPath + File.separatorChar + justFileName); > >> > >> A la "Rife" : > >> import com.uwyn.rife.tools.FileUtils; > >> URL resource = > >> getClass().getClassLoader().getResource("model/WordList.txt"); > >> final String wordlist = FileUtils.readString(resource); > >> > >> Please could you tell me what are methods and usages with Tapestry ? > >> > >> Thanks > >> cyrille > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > >> For additional commands, e-mail: [EMAIL PROTECTED] <mailto:[EMAIL > >> PROTECTED]> > >> > >> > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] >