struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sattanari <katkam.satyanaray...@gmail.com>
Subject Re: Struts 2 Jasper Reports Plugin
Date Sat, 09 Aug 2008 09:44:42 GMT

hi
iam sending one example have a look at this


package com.kogent.action;
import com.opensymphony.xwork2.*;
import net.sf.jasperreports.engine.JasperCompileManager;
import java.text.*;
import java.sql.*;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.interceptor.*;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.design.JasperDesign;



public class ReportsAction  extends ActionSupport implements
ServletRequestAware, ServletResponseAware
{
	
	private HttpServletRequest request=null;
	private HttpServletResponse response=null;
	Connection con=null;
	Statement stmt=null;
	ResultSet rs=null;
	
	JasperReport jasperReport;
	JasperPrint jasperPrint;
	JasperDesign jasperDesign;
	
	private List<MonthlyStatement> myList=null;
	
	private List<Dummy> dummyList=null;
	
	private String fromdate;
	private String todate;
	private String reporttype;
	private String accountnumber;
	public String getAccountnumber() {
		return accountnumber;
	}
	public void setAccountnumber(String accountnumber) {
		this.accountnumber = accountnumber;
	}
	public String getFromdate() {
		return fromdate;
	}
	public void setFromdate(String fromdate) {
		this.fromdate = fromdate;
	}
	public String getReporttype() {
		return reporttype;
	}
	public void setReporttype(String reporttype) {
		this.reporttype = reporttype;
	}
	public String getTodate() {
		return todate;
	}
	public void setTodate(String todate) {
		this.todate = todate;
	}
	
	
	 public void setServletRequest(HttpServletRequest request)
	 {
		 this.request=request;
	 }
	 
	 public void setServletResponse(HttpServletResponse response)
	 {
		 this.response=response;
	 }
	
	public String execute() 
	{
		
		System.out.println("************ Execute Method is Called
***************");
		
		myList = new ArrayList<MonthlyStatement>();
		dummyList = new ArrayList<Dummy>();
		
		Dummy dummy = new Dummy();
		dummy.setTxreference("some Referece");
		dummy.setTxdetails("detauks");
		dummy.setTxamount("200");
		
		dummyList.add(dummy);
		String dir = request.getRealPath("/");
		
		
		try
		{
			
			
		/*Class.forName("com.mysql.jdbc.Driver");
		con= DriverManager.getConnection("jdbc:mysql://localhost:3306/test",
"root","123456");
		stmt= con.createStatement();
		
		SimpleDateFormat sdf 		= new SimpleDateFormat("yyyy-MM-dd");
		java.util.Date fdate 		= sdf.parse(fromdate);
		java.util.Date tdate		= sdf.parse(todate);
		
		java.sql.Timestamp fromDate = new java.sql.Timestamp(fdate.getTime());
		java.sql.Timestamp toDate	= new java.sql.Timestamp(tdate.getTime());
		
		
		String query = "select * from monthlystatement where date between
'"+fromDate+"' AND '"+toDate+"' ";
		
		 rs = stmt.executeQuery(query);
		while(rs.next())
		{
			
		
			MonthlyStatement monthStatement = new MonthlyStatement();
			//monthStatement.setDate(date)
			monthStatement.setTransactiondetails(rs.getString("transactiondetails"));
		
monthStatement.setTransactionreference(rs.getString("transactionreference"));
		    monthStatement.setTransactionamount(rs.getString("amount"));
		   // monthStatement.setDate(rs.getTimestamp("date"));
		    
		    myList.add(monthStatement);
		    
		    System.out.println(" SIZE OF LIST IS========>" + myList.size());
		    
		
		}
		*/
			
		
	
JasperCompileManager.compileReportToFile(dir+"/jasper/our_jasper_template.jrxml",dir+"/jasper/our_compiled_template.jasper");
		
		/* load JasperDesign from XML and compile it into JasperReport
		jasperDesign =
JRXmlLoader.load(dir+"/jasperReports/our_jasper_template.jrxml");
		jasperReport = JasperCompileManager.compileReport(jasperDesign);
		 
    	 fill JasperPrint using fillReport() method
	     jasperPrint =
JasperFillManager.fillReport(jasperReport,parameters,con);
		 
		JasperExportManager.exportReportToPdfFile(jasperPrint,
dir+"/jasperReports/output.jasper");
		response.setContentType("application/pdf");
        */
		 
		}
		
		catch(Exception e)
		{
			System.out.println(e);
		}
		
		
		return SUCCESS;
	}
	
	public List<MonthlyStatement> getStatement()
	{
		System.out.println(" Returning Size Is ==============>" + myList.size());
		return myList;
	}
	
	public List<Dummy> getDummyList()
	{
		return dummyList;
	}

}

-- 
View this message in context: http://www.nabble.com/Struts-2-Jasper-Reports-Plugin-tp9918148p18903505.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message