abdi shaikh

Greenhorn
+ Follow
since Feb 28, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by abdi shaikh

it means that the report is getting displayed. report is in the pdf format at the same time my project is also working. but when i close my report (i.e the pdf) tomcat is shutdown automatically. please help!
14 years ago
i have creatd a code for jasper report. The report is getting displayed but when i close my report (which is in the pdf format) i loose connection with apache tomcat 5.0. I have to re-establish the connection. my project is stuck here for many days. Can anyone please help me out. Thank you in advance!


My code here :



import java.sql.*;
import net.sf.jasperreports.view.*;
import net.sf.jasperreports.view.save.*;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.xml.*;
import net.sf.jasperreports.engine.design.*;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;
public class rptinst extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException
{
HttpSession session=request.getSession();


String branchid=(String)session.getAttribute("branchid");
String staffid=(String)session.getAttribute("staffid");
String name=(String)session.getAttribute("name");
String studname=(String)session.getAttribute("stud_name");
String studid=(String)session.getAttribute("stud_id");
String type=(String)session.getAttribute("type");

session.setAttribute("branchid",branchid);
session.setAttribute("staffid",staffid);
session.setAttribute("name",name);
session.setAttribute("type",type);
session.setAttribute("stud_id",studid);
session.setAttribute("stud_name",studname);

String databaseName = "pims" ;
String userName = "root";
String password = "";
String reportFile = null;
// String reportFile = "C:/Program Files/Apache Software Foundation/Tomcat 5.0/webapps/PIMS/Reports/Untitled_report_1.jrxml";

//runReport(databaseName, userName, password, reportFile);
System.setProperty("jasper.reports.compile.class.path", (String)request.getSession().getServletContext().getAttribute("org.apache.catalina.jsp_classpath"));

PrintWriter out=null;
try{


if(type.equals("fresh"))
{

reportFile = "C:/Program Files/Apache Software Foundation/Tomcat 5.0/webapps/PIMS/resources/firstinst.jrxml";
}


Map mpDetailSp;
out=response.getWriter();
mpDetailSp = new HashMap();
out.println("before start up");
JasperDesign jasperDesign = JRXmlLoader.load(reportFile);
out.println("AFTER Loadinf jasper design");
System.out.println("AFTER Loadinf jasper design");
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
Connection jdbcConnection = connectDB(databaseName, userName, password);

mpDetailSp.put("stud_id",new String (studid));
mpDetailSp.put("branch_id",new String (branchid));
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, mpDetailSp, jdbcConnection);

out.println("after fill manager");
JasperViewer.viewReport(jasperPrint);
out.println("after view manager");
}
catch(Exception ex) {
String connectMsg = "Could not create the report " + ex.getMessage() + " " + ex.getLocalizedMessage();
System.out.println(connectMsg);
out.println(ex.getMessage());
out.println("exception details" +ex);
System.out.println("exception details" +ex);
ex.printStackTrace();
}


return;
}

public static Connection connectDB(String databaseName, String userName, String password) {
Connection jdbcConnection = null;
try{
String url="jdbc:mysql://localhost/"+databaseName+"?user="+userName+"&password="+password;
jdbcConnection=DriverManager.getConnection(url);
String DRIVER = "org.gjt.mm.mysql.Driver";
Class.forName(DRIVER).newInstance();

}catch(Exception ex) {
String connectMsg = "Could not connect to the database: " + ex.getMessage() + " " + ex.getLocalizedMessage();
System.out.println(connectMsg);
}
return jdbcConnection;
}
public static void runReport(String databaseName, String userName, String password,String reportFile) {
try{Map mpDetailSp;
mpDetailSp = new HashMap();
JasperDesign jasperDesign = JRXmlLoader.load(reportFile);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
Connection jdbcConnection = connectDB(databaseName, userName, password);
mpDetailSp.put("branch_id",new String ("branch01"));
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, mpDetailSp, jdbcConnection);
JasperViewer.viewReport(jasperPrint);
}catch(Exception ex) {
String connectMsg = "Could not create the report " + ex.getMessage() + " " + ex.getLocalizedMessage();
System.out.println(connectMsg);
}
}


}
14 years ago