Access file in WebContent folder from a servlet

前端 未结 3 744
生来不讨喜
生来不讨喜 2021-02-06 04:56

I\'m trying to generate a PDF document using FOP. The pdf generation code is kept in a servlet and the xsl is in a specific folder in the WebContent folder.

How can I a

3条回答
  •  不知归路
    2021-02-06 05:46

    To get the path you can just do:

    String path = s.getServletContext().getRealPath("/WEB-INF/somedir/hdfeeh");         
    

    s is the class that implements HTTPServlet.You can also use this.getServletContext() if its your servlet class.

    Then pass this as a parameter.

    As far as using dynamically generated XML, the library you're using should support using an input stream, write your XML, convert it to a byte array, then wrap it in a ByteArrayInputStream and use this.

提交回复
热议问题