从Servlet中的Web内容文件夹中读取HTML文件

时间:2016-06-07 10:17:22

标签: servlets resources webcontent

我正在尝试从war文件中读取.html文件。我使用了下面的代码,但它不起作用。

项目结构:

Project
|_war
    |_Pages
      |_HtmlFiles
        |_sample.html

我的代码:

InputStream inputStream = EmailMessages.class.getClassLoader()
        .getResourceAsStream("/sample.html");

2 个答案:

答案 0 :(得分:1)

根文件夹位于类路径上,请尝试以下方法:

this.getClass().getResourceAsStream("/Pages/HtmlFiles/sample.html");

答案 1 :(得分:-1)

将文件放在void f( int (*fp)() ) {} 文件夹中,导出战争时,您可以在src\main\resources目录下的resources目录中找到您的文件。现在阅读像这样的html文件,

WEB-INF\classes