2001 JI Open Discussion Posted August 16, 2006 Share Posted August 16, 2006 By: Uniq - uniq_2002 connected to database in Web Apllication 2002-09-05 03:32Hi, i'll try to connect to database with Jasper Report in web base. My code is : (jasperWeb.jsp) <%@ page errorPage="jasperError.jsp" %> <%@ page import="dori.jasper.engine.*" %> <%@ page import="java.util.*" %> <%@ page import="java.io.*" %> <%@ page import="java.sql.*" %> <%@ page import="java.awt.*" %> <%@ page import="JasperWeb" %> <% File reportFile = new File(application.getRealPath("/FirstJasper.jasper")); Map parameters = new HashMap(); parameters.put("ReportTitle", "...Report..."); parameters.put("BaseDir", reportFile.getParentFile()); byte[] bytes = JasperRunManager.runReportToPdf( reportFile.getPath(), parameters, getConnection() ); ........... %> in file JasperWeb.java .............. public static Connection getConnection() throws ClassNotFoundException, SQLException { //connection to postgre String driver = "org.postgresql.Driver"; String connectString = "jdbc:postgresql://"; String user = ""; String password = ""; Class.forName(driver); Connection conn = DriverManager.getConnection(connectString, user, password); return conn; } ..................... if i running the code, i am getting error "import JasperWeb is not found" . its like i never import JasperWeb.class. so what i must do ?? if connection to database in jasperWeb.jsp and deleted <%@ page import="JasperWeb" %> its running. so i must take the connection in jsp ?? But i want take the connection in the class and import in jsp....:-) oh somenthing missing, i'll try to use <jsp:useBean id="con" class="JasperWeb" scope = "page"/> ... but i am still get the same error... thanks for any appreciate...;-) regards, uniQ By: Teodor Danciu - teodord RE: connected to database in Web Apllication 2002-09-05 04:09 Hi, Make sure the JasperWeb class is available in the classpath when you run your JSP. You could place the JasperWeb.class file in the WEB-IN/classes directory of your Web application for example. And also make sure you are calling the getConnection() method like this: JasperWeb.getConnection() From what I see, this is not the case. Good luck! Teodor By: Uniq - uniq_2002 RE: connected to database in Web Apllication 2002-09-09 18:22Thanks theodord...:-) i sorry...i am wrong.. my class JasperWeb is in WEB-INFJasperWeb and then i move the class to : WEB-INFclassesJasperWeb.. its done.. sorry if i am disturbing u...;-) Regards, uniQ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now