2

我正在使用 JSF 1.2 和 Seam 2.2.2

如果我可以在代码中渲染页面并将输出保存到文件而不是将其发送给客户端,那么我会感到困惑。

//三连

4

1 回答 1

4

最简单的方法是自己发送一个 HTTP 请求(在 localhost 上执行时应该特别便宜)。

InputStream input = new URL("http://localhost:8080/context/page.jsf").openStream();
// ...

如果您想在与当前客户端相同的会话中请求它并且您的服务器接受 URL 重写,请改用以下 URL。

InputStream input = new URL("http://localhost:8080/context/page.jsf;jsessionid=" + session.getId()).openStream();
// ...

或者,如果您的服务器不接受 URL 重写,而只接受 cookie,那么请改用以下方法。

URLConnection connection = new URL("http://localhost:8080/context/page.jsf").openConnection();
connection.setRequestProperty("Cookie", "JSESSIONID=" + session.getId());
InputStream input = connection.getInputStream();
// ...
于 2012-11-25T19:50:50.420 回答