Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LoadingProblem of a TextFile in WebApp! 1

Status
Not open for further replies.

flowingmind

Programmer
Jun 2, 2004
2
DE
hi !
Want to load a txt-File in a WebApp with FileInputStream
using a relative path. But the file is not found .
Where do I have to place it in the directory of my WebApp?
And what then is the relative path to it?

thx dirk
 
You can obtain a file system path for the context root of you webapp like this :

Code:
<%

ServletContext sc = getServletConfig().getServletContext();
String path = sc.getRealPath("/");
out.println(path);

%>
 
Oh I made amistake and redflagged the post from sedj.

The Answer didn't help me.
i wan't to load the file not from a jsp-pages.
Using Struts I want to load from a class which is instanciated in an ActionClass while performing the execute()-method.

thx and sorry for the redflag (i understood wrong )

Dirk
 
Well, you didn;t say you were doing it from Struts ...

In any case, the procedure is similar using Struts ...

Code:
// where request is your HttpServletRequest object from the Action classes's execute() method ...
ServletContext sc = request.getSession().getServletContext();
String path = sc.getRealPath("/");
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top