• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

tomcat connection

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}
}


}
 
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
UseCodeTags
 
Misha Ver
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic