File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes tomcat connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "tomcat connection" Watch "tomcat connection" New topic
Author

tomcat connection

abdi shaikh
Greenhorn

Joined: Feb 28, 2010
Posts: 2
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

Joined: Mar 03, 2008
Posts: 470
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

Joined: Feb 28, 2010
Posts: 2
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

Joined: Jan 10, 2002
Posts: 60785
    
  65

UseCodeTags

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Misha Ver
Ranch Hand

Joined: Mar 03, 2008
Posts: 470
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

Joined: Mar 22, 2000
Posts: 12761
    
    5
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: tomcat connection
 
Similar Threads
unable to read file from war file
Unable to execute jar file....got following stack trace.
Problem with Jasper report
org.xml.saxSAXNotRecognEx
Unable to execute jar file....got following stack trace.