Pentaho provides different API’s, which can be used in JSP pages. We can easily pass parameter from a JSP page to Pentaho reports using these APIs. Below are the steps
1. Create a .xaction file in design studio.
2. Add a Process Input as NAME.
3. The query will be as follows:
SELECT "EMP"."EMPNO", "EMP"."ENAME", "EMP"."SAL", "EMP"."DEPTNO"
FROM "EMP" where "EMP"."ENAME"={NAME}
4. Create a HTML file with following code:
<HTML>
<BODY BGCOLOR="pink">
<br><br><br><br><br><br><br><br>
<Center>
<FORM ACTION="http://localhost:8080/pentaho/sumeet_session" METHOD=post>
ENTER YOUR NAME : <INPUT TYPE="TEXT" NAME="NAME" SIZE=20>
<P><INPUT TYPE="SUBMIT" value="Submit">
</FORM>
</center>
</BODY>
</HTML>
5. Create a JSP (sumeet_session.jsp) page with following code:
<%@ page import=
"java.util.Hashtable,
java.util.Calendar
,java.util.Date
,java.util.Vector
,java.sql.*
,java.text.SimpleDateFormat
,javax.naming.Context
,javax.naming.InitialContext
,javax.sql.DataSource
,java.util.*" pageEncoding="UTF-8"%>
<%@ page language="java"
import="java.util.ArrayList,
java.util.Date,
java.io.ByteArrayOutputStream,
org.pentaho.platform.util.web.SimpleUrlFactory,
org.pentaho.platform.web.jsp.messages.Messages,
org.pentaho.platform.engine.core.system.PentahoSystem,
org.pentaho.platform.uifoundation.chart.DashboardWidgetComponent,
org.pentaho.platform.web.http.request.HttpRequestParameterProvider,
org.pentaho.platform.web.http.session.HttpSessionParameterProvider,
org.pentaho.platform.api.engine.IPentahoSession,
org.pentaho.platform.web.http.WebTemplateHelper,
org.pentaho.platform.util.VersionHelper,
org.pentaho.platform.util.messages.LocaleHelper,
org.pentaho.platform.engine.core.solution.SimpleParameterProvider,
org.pentaho.platform.engine.services.solution.SolutionHelper,
org.pentaho.platform.uifoundation.chart.ChartHelper,
org.pentaho.platform.web.http.PentahoHttpSessionHelper"
%>
<HTML>
<BODY>
<%
String name = request.getParameter( "NAME" );
session.setAttribute( "NAME", name );
%>
<%
response.setCharacterEncoding(LocaleHelper.getSystemEncoding());
String baseUrl = PentahoSystem.getApplicationContext().getBaseUrl();
IPentahoSession userSession = PentahoHttpSessionHelper.getPentahoSession( request );
HttpRequestParameterProvider requestParameters = new HttpRequestParameterProvider( request );
HttpSessionParameterProvider sessionParameters = new HttpSessionParameterProvider( userSession );
SimpleParameterProvider parameters = new SimpleParameterProvider();
// pass the NAME to the report
parameters.setParameter( "outputType", "html" );
parameters.setParameter( "NAME",name);
// create an output stream for the report content
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ArrayList messages = new ArrayList();
// run the action sequence 'samples/dashboard/jsp/report.xaction'
SolutionHelper.doAction("SessionPara","","session_para.xaction","sumeet_session1.jsp",parameters,outputStream,userSession,messages, null ) // write the report content into this page
out.write(outputStream.toString());
%>
</BODY>
</HTML>
6. Save the jsp file at following location:
biserver-ce\tomcat\webapps\pentaho\jsp
7. Make the required changes into web.xml file.
8. Run the html file.
9. Enter the name in text box and click submit button.
Hope this article will make your task easier.