How to determine the file path relative to the web application. For example, a WEB-INF file stores a config.xml file with database configurations. It is necessary to determine the path config.xml from the servlet. How to do it?
1 answer
I haven’t written servlets for a long time - I forgot already :)
Enter in the logs of your servlet / JSP line:
ServletContext.getRealPath("\\");
and you will get the path of the context root in the server file system, relative to it already and position your file.
- probably not exactly what I want. I don't want to get attached to physical directories, I know that there is myClass.class.getRealPath (). How then to climb up the catalogs? ../? - uladzimir
- Well, if the physical root path is something like
~/myfolder/myserver
, then you need to specify/web-inf/config.xml
and in a real system it will point to the path~/myfolder/myserver/web-inf/config.xml
, not? - Barmaley - Yes, that is right. thanks - uladzimir
|