[英]Where should I place a pdf to be download in a Java web app project?
[英]Where should I place external xslt file in java web app?
我在/ WEB-INF / classes /文件夾中有一個外部XSLT文件。 如何使用相對路徑訪問文件?
File xsltfile = new File("xhtml2fo.xsl");
FileNotFoundException at D:\\Softwares\\eclipse\\xhtml2fo.xsl
給出FileNotFoundException at D:\\Softwares\\eclipse\\xhtml2fo.xsl
。
我正在運行tomcat服務器上的webapp。
您可以使用ServletContext#getRealPath(“ /”)來獲取WebContent
根目錄的路徑
然后簡單地使用這個
String pathToFile = servletContext.getRealPath("/") + "/WEB-INF/classes/ folder/html2fo.xsl";
File file=new File(pathToFile);
我的tomcat啟動配置中的工作目錄為D:/ Softwares / eclipse,因此從同一目錄中選擇了相對路徑。 在將工作目錄更改為$ {workspace_loc:mywebapp / WebContent / WEB-INF}並將文件位置更改為“ classes / xhtml2fo.xsl”后,該文件便起作用了
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.