--- Arreglado, el servidor Tomcat no estaba bien
Hola a todos, llevo 2 semanas con Jasper Reports y me ha surgido un problema a la hora de crear una aplicación web que le pase a un servlet mediante un stream los parámetros de conexión, la base de datos y el fichero jrxml a interpretar, este es el codigo del servlet:
import java.io.File;
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.*;
import javax.servlet.*;
import java.sql.*;
import net.sf.jasperreports.engine.util.*;
import net.sf.jasperreports.view.JasperViewer;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.export.JRHtmlExporter;
import net.sf.jasperreports.engine.JRExporterParameter;
import org.apache.commons.fileupload.FileUpload;
import org.apache.commons.fileupload.servlet.ServletFileU pload;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFac tory;
public class Ser extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void destroy() {
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
public void processRequest(HttpServletRequest req,HttpServletResponse res)
{
try{
// Check that we have a file upload request
boolean isMultipart = ServletFileUpload.isMultipartContent(req);
if (isMultipart)
{
//PrintWriter out2 = res.getWriter();
// Create a factory for disk-based file items
FileItemFactory factory = new DiskFileItemFactory();
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// Parse the request
List /* FileItem */ items = upload.parseRequest(req);
// Process the uploaded items
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
String databaseName = "";
String userName = "";
String password = "";
if (item.isFormField()) {
String name = item.getFieldName();
String value = item.getString();
if (name.equals("databaseName")){
databaseName = value;
}else if (name.equals("userName")){
userName = value;
}else if (name.equals("password")){
password = value;
}
// out2.println("Form field:" + name + " " + value);
} else {
InputStream uploadedStream = item.getInputStream();
JasperPrint jasperPrint = returnReportPrint(databaseName,userName,password,u ploadedStream);
PrintWriter out = res.getWriter();
JRHtmlExporter exporter = new JRHtmlExporter();
exporter.setParameter(JRExporterParameter.JASPER_P RINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_W RITER,out);
exporter.exportReport();
out.close();
}
}
}
else{
System.out.println("No Multipart ");
}
}catch(Exception e){
System.out.println("Error " + e.getMessage());
}
}
public JasperPrint returnReportPrint(String databaseName, String userName, String password, InputStream inputStream) {
JasperPrint jasperPrint = new JasperPrint();//null;
try{
JasperDesign jasperDesign = JRXmlLoader.load(inputStream);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
Connection jdbcConnection = connectDB(databaseName, userName, password);
jasperPrint = JasperFillManager.fillReport(jasperReport, null, jdbcConnection);
}catch(Exception ex) {
String connectMsg = "Could not create the report stream " + ex.getMessage() + " " + ex.getLocalizedMessage();
System.out.println(connectMsg);
}
return jasperPrint;
}
public Connection connectDB(String databaseName, String userName, String password) {
Connection jdbcConnection = null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
jdbcConnection = DriverManager.getConnection(databaseName,userName, password);
}catch(Exception ex) {
String connectMsg = "Could not connect to the database: " + ex.getMessage() + " " + ex.getLocalizedMessage();
System.out.println(connectMsg);
}
return jdbcConnection;
}
}
Y me sale el siguiente error:
14-ago-2006 13:51:15 org.apache.commons.digester.Digester startElement
GRAVE: Begin event threw exception
java.lang.NullPointerException
at org.apache.commons.digester.FactoryCreateRule.getF actory(FactoryCreateRule.java:489)
at org.apache.commons.digester.FactoryCreateRule.begi n(FactoryCreateRule.java:389)
at org.apache.commons.digester.Digester.startElement( Digester.java:1361)....
....
....
Could not create the report stream Error at line 5 char 36: null Error at line 5 char 36: null.
Para todo jrxml que le mando, cuando empieza a interpretar la primera etiqueta despues de la de <jasperreport>,
, llevo 3 dias rayado con el mismo problema, ¿alguien sabe que puede ser?