Pessoal estou tentando passar um objeto java para uma applet. Eu preciso disso pois quero enviar um relatorio direto para uma impressora (padrão) do usuário. Através de algumas pesquisas achei que tenho que serializar o objeto que quero (transformalo) em String passar por parametros e recebe-lo na Applet. Então olha como eu fiz.
1°- Classe que gera o Objeto Java e Serializa:
public String executar() throws Exception{
String a = "";
if (layout == null) throw new Exception("Relatório vazio.");
String nameRel = getRandom(20);
parameters.put("REPORT_LOCALE", new Locale("pt", "BR"));
JasperPrint jasperPrint = JasperFillManager.fillReport(layout, parameters, conexao);
try {
FileOutputStream fileStream = new FileOutputStream(nameRel);
ObjectOutputStream os = new ObjectOutputStream(fileStream);
os.writeObject(jasperPrint);
a = os.toString();
os.close();
} catch (Exception ex) {
ex.printStackTrace();
}
return a;
}
public void init() {
try {
getParameters();
FileInputStream fIn = new FileInputStream(sJasperPrint);
ObjectInputStream in = new ObjectInputStream(fIn);
JasperPrint jasperPrint = (JasperPrint) in.readObject();
JasperPrintManager.printPage(jasperPrint, 0, propPrint);
} catch (FileNotFoundException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (JRException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
18/07/2012 14:37:00 com.smarapd.impdireto.applet.Main init
SEVERE: null
java.io.FileNotFoundException: java.io.ObjectOutputStream@c3d062 (O sistema não pode encontrar o arquivo especificado)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at com.smarapd.impdireto.applet.Main.init(Main.java:37)
at sun.applet.AppletPanel.run(AppletPanel.java:417)
at java.lang.Thread.run(Thread.java:619)
Será que alguem sabe como fazer isso ?