2009-05-04 93 views
3

我想在JSP页面中包含文件的内容。 通常情况下,我会使用类似:在JSP中包含文件的内容

<jsp:include page="<%= path_to_file %>" /> 

但是,这不会在这里工作,因为我想包括 该文件是在网络部署外。

我见过的最丑陋的解决方案是这样的:

<td> 
<% BufferedReader br = new BufferedReader(new FileReader(new File(path_to_file))); 
    String line = br.readLine(); 
    while (line != null) { %> 
    <% out.println(line); %> 
    <% line = br.readLine(); } %> 
</td> 
<% } catch (IOException e) { %> 
<td> 
    <%= e %> 
</td> 
<% } %> 

但我真的不希望这样做。

感谢

回答

0

可以包括在你的发行版的符号路径指向你的外部路径。

0

为了避免丑陋的scriptlet代码,您可以编写一个小标记(在Java中,扩展SimpleTagSupport),仅用于包含来自外部路径的任意文件。

然后,你可以写

<my:include page="<%= path_to_file %>" />