【问题标题】:jsp - Combining include file and jsp methodsjsp - 结合包含文件和 jsp 方法
【发布时间】:2016-08-12 03:07:11
【问题描述】:

我正在尝试在包含的文件上运行 jsp 方法。我该怎么做?

我有我的包含文件:

<%@ include file="/foobar/Foo.bar" %>

我有我的foo(String str) 方法。

现在的问题是,我如何在文件/foobar/Foo.bar 上调用foo()

提前致谢!

【问题讨论】:

    标签: file jsp include


    【解决方案1】:

    我创建了一个方法,而不是包含文件:

    public String readResource(String resource){
            try{
                BufferedReader in = new BufferedReader(new InputStreamReader(getServletContext().getResourceAsStream(resource)));
            String line = null;
    
            String data = "";
            while((line = in.readLine()) != null) {
                if(data!="")data+="\n";
                data+=line;
            }
            return data;
            }catch(IOException e){
                return "";
            }
        }
    

    然后我使用了&lt;%=foo(readResource("/foobar/Foo.bar"))%&gt;

    【讨论】:

      猜你喜欢
      • 2015-02-23
      • 1970-01-01
      • 2017-10-25
      • 2016-02-19
      • 2017-02-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多