FileInputStream and FileNotFound Exception

后端 未结 5 2010
慢半拍i
慢半拍i 2021-01-28 11:05

I am trying to retrieve a jrxml file in a relative path using the following java code:

 String jasperFileName = \"/web/WEB-INF/reports/MemberOrderListReport.jrxm         


        
5条回答
  •  甜味超标
    2021-01-28 11:44

    You're trying to treat the jrxml file as an object on the file-system, but that's not applicable inside a web application.

    You don't know how or where your application will be deployed, so you can't point a File at it.

    Instead you want to use getResourceAsStream from the ServletContext. Something like:

    String resourceName = "/WEB-INF/reports/MemberOrderListReport.jrxml"
    InputStream is = getServletContext().getResourceAsStream(resourceName);
    

    is what you're after.

提交回复
热议问题