1. Description of the problem
In the Report development tool Finereport, if there are several different reports, each report has a common item to choose from, such as date and time. When we want to select the time of the first report, the default time for other reports changes to the time of the first report selection, how do we do this?
2. Realization of Ideas
Can be used to assign values to the session to achieve. The parameter control for the first report increases the post-edit event for the servlet that passes the value through the Ajax URL to the background, the servlet gets the value passed by the Ajax and saves it to the session, and the subsequent report gets the session value at the control value of the parameter.
3. Implementation steps
3.1 Ajax Value setting
Open a template with parameters, such as open Template:%fr_home%\webreport\web-inf\reportlets\doc\primary\parameter\parameter.cpt.
Click on the parameter interface, set the control to the TextBox control, add the text box control to the post-editing event, the specific JS as follows:
1.var Str=this.getvalue (); Gets the value of the current control 2.fr.ajax ({3. URL: "servlet/session?id=" +fr.cjkencode (str),//pass the value to the session in the servlet});
Note: If you want to preview the report and also write the data to the session, without the need for asynchronous loading, you can add Async:false to Ajax.
3.2 Get value and save to session
Create a new class named session with the following code:
1.import javax.servlet.http.httpsession; 2.import java.io.ioexception; 3.import java.io.printwriter; 4.import java.util.ResourceBundle; 5.import java.lang.string; 6.import javax.servlet.servletexception; 7.import javax.servlet.http.httpservlet; 8. import javax.servlet.http.httpservletrequest; 9.import javax.servlet.http.httpservletresponse; 10. 11.import com.fr.stable.codeutils; 12.import com.fr.web.utils.webutils; 13. 14.public class session extends HttpServlet { 15. public&Nbsp;void doget (httpservletrequest request, 16. httpservletresponse response) 17. throws IOException, ServletException 18. { 19. Response.setcontenttype ("text/html; charset=gb2312"); 20. 21. printwriter out = response.getwriter () ; 22. out.println ("Compile the Session.java class and place the compiled Session.class under the%FR _home%\webreport\web-inf\classes directory.
3.3 Configuring the servlet to access session assignment
Open the Web. XML under%FR _home%\webreport\web-inf\ and add the following code:
1.<servlet> 2. <servlet-name>session</servlet-name> 3. <servlet-class>session</servlet-class> 4. </servlet> 5. 6. <servlet-mapping> 7. <servlet-name>session</servlet-name> 8. <url-pattern>/servlet/session</url-pattern> 9. </ Servlet-mapping>
Note: When writing a Java class file, if it is stored under a specific package, such as com/fr/data below, in addition to the need to place the class file in the corresponding location, The Servlet-class tags in the Web. xml file also need to be modified, such as com.fr.data.session.
3.4 Get Session Value
In another parametric template such as%fr_home%\webreport\web-inf\reportlets\doc\primary\parameter\ PARAMETER1.CPT deletes the default value for the regional parameter in the dataset, and selects the formula in the control value of the parameter control and enters $sessionname (the name of the session in the servlet), such as:
650) this.width=650; "alt=" Picture 1.png "src=" http://www.cognoschina.net/home/attachment/201509/30/174759_ 1443577486ihym.png "style=" Word-spacing:normal;border:0px;vertical-align:middle;height:auto; "/>
Note: SessionName refers to SessionName in the Java class.
3.5 Effect View
Page Preview Parameter.cpt, after entering China in the text box, and then previewing PARAMETER1.CPT, you can see that the text box shows China, such as:
650) this.width=650; "alt=" Picture 2.png "src=" http://www.cognoschina.net/home/attachment/201509/30/174759_ 1443577495hnah.png "style=" Word-spacing:normal;border:0px;vertical-align:middle;height:auto; "/>
Assigning values to sessions in a report to implement parameter sharing between reports