Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

tomcat connection

 
abdi shaikh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
}


}
 
Misha Ver
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "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"
 
abdi shaikh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
 
Misha Ver
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abdi shaikh wrote:tomcat is shutdown automatically.


I still don't understand what do you mean. Any error messages, log files?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i loose connection with apache tomcat 5.0.


Perhaps I am misunderstanding but I am assuming you mean the browser "connection" - that is just an address, there is no active connection. When Tomcat finished sending the pdf file, that was the end of the response. Presumably Tomcat is still running but you lost the browser connection.

You could
1. open the PDF as a separate tab so closing the PDF tab returns to the previous page.
2. use the browser back button to recover the previous page.

Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic