jsp - Cannot get the real path of a file in the project folder -
Within a jsp file I am trying to navigate to loading the XML file. The location of the JSP file
/ project folders / playout / app names / indexes Jsp The location of the XML file
/ project folders / data / file / mefile. Xml The location of the project folder is different in each environment, Example: The location in my local PC is:
c: \ myApps \ BPServer \ tomcat \ Webapps \ projectFolder When I use the following code:
& lt; C: set var = "xmlfile" value = "$ {pageContext.request.contextPath} /data/files/myfile.xml" /> The value of the xmlfile is set to:
c: \ projectFolder \ data \ files \ myfile.xml < P> However, the odd thing is that if I use xmlfile as href then the correct path and file is located: Any ideas how to work, I can get the correct file path from the following:
boolean canLocateFile = fileExists (xmlfile); Public stable Boolean fileexists (string file path) {filef = new file (file path); Return f.exists (); }
You can get the root path of the application from you.
If you have a relative path to the file, you can get its actual path.
Example:
string realpath = servletContext.getRealPath ("/ data / files / myfile XML"); You can also get the root path of your application. The root path can then be used to refer to your file. Example:
string root path = universaltext.gatecontextpath (); String filePath = rootPath + "/data/files/myfile.xml"; If the servlet contract is not accessible to you in your class, you can store the root path of your application in the int-param or property, and use it.
Comments
Post a Comment