Error getting file name using getServletConfig

后端 未结 2 1734
轻奢々
轻奢々 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 19:38

    The Path you give should be servlet path. Normally, servlets paths have forward slash /.

    Please try this /rpts/report1.jasper".

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题