Search code examples
jsfseam

Render JSF Page in backend and save the output to file


I am using JSF 1.2 with Seam 2.2.2

And woundering if i can render a page from with in the Code and Save the output to a file instead of sending it to the client.

//Trind


Solution

  • The easiest way would be just sending a HTTP request yourself (which should be particularly cheap when performing on localhost).

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

    If you'd like to request it within the same session as the current client and your server accepts URL rewriting, then use the following URL instead.

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

    Or if your server doesn't accept URL rewriting, but accepts cookies only, then use the following approach instead.

    URLConnection connection = new URL("http://localhost:8080/context/page.jsf").openConnection();
    connection.setRequestProperty("Cookie", "JSESSIONID=" + session.getId());
    InputStream input = connection.getInputStream();
    // ...