Error getting file name using getServletConfig

后端 未结 2 1738
轻奢々
轻奢々 2021-01-24 19:20

I am using JasperReport for generation reports in Java Web Application.

I have a following line to get report file.

JasperReport report = (J         


        
2条回答
  •  终归单人心
    2021-01-24 20:03

    Java language (and others) needs \\ (double backslash) in Strings in order to read a single \. Your first way should change to

    JasperReport report = (JasperReport) JRLoader.loadObject(getServletConfig()
        .getServletContext().getRealPath("\\rpts\\report1.jasper"))
    

    Still, it would be better to check paths using / or even better using File#separator as shown here: File.separator vs Slash in Paths

提交回复
热议问题