I. Description
Session saves the key-value attribute, and I hope to get the value of the key in the session in the report.
II. Situation one
Get the value in the Session directly in the template.
1. Idea
The report application is integrated into the user system and shares the same session. At this time, the value of the session can be directly obtained in the report.
If key a is saved in the session and its value is 123, then use =$a in our report to directly get the value of a in the session.
III. Situation two
In the web page, the value in the Session is first obtained and then passed to the report in the iframe.
1. Idea
Taking JSP as an example, the value of key in the Session can be obtained through session.getAttribute(String key) and grafted into the src of the report iframe embedded in the JSP.
2. Example
In the user system, through session.setAttribute(String key,Object value); saves information in the Session such as fine_username=Anna,
Get fine_username through session.getAttribute("fine_username") in JSP, and then pass it to the report. The code example is as follows:
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <html> <body> <iframe width=100% height=100% src='/webroot/decision/view/report?viewlet=getkey.cpt&country=<%=session.getAttribute("fine_username")%>'> </iframe> </body> </html>
The fine_username value can be obtained in the report template, as shown in the following figure:
The effect is as follows:
Note: JSP files can only be parsed by the server.
IV. Situation three: Get Session in JS
Normal cpt template, JS get Session method:
contentPane.currentSessionID
Note: If the FineReport is embedded in the iframe of the HTML page, then the Session can be obtained through document.getElementById('reportFrame').contentWindow.contentPane.currentSessionID
frm template, the method for JS to obtain Session is:
_g().sessionID