Capture current JSF page content

后端 未结 4 1554
孤城傲影
孤城傲影 2021-01-25 05:37

I want to capture the current page and send it to an application that converts it to pdf.

This is what I am using:

FacesContext facesContext=FacesContext         


        
4条回答
  •  别那么骄傲
    2021-01-25 05:44

    Just request the page in the same HTTP session as the current request. If your webapp supports URL rewriting (as by default), then just append session ID as jsessionid path fragment:

    String sessionId = ((HttpSession) externalContext.getSession()).getId();
    InputStream input = new URL("http://localhost:8080/context/page.jsf;jsessionid=" + sessionId).openStream();
    // ...
    

    Or if your webapp doesn't accept URL rewriting, but accepts cookies only, then set it as a request cookie the usual way:

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

    Note that I removed setDoOutput() since you don't seem to be interested in performing a POST request.

提交回复
热议问题