Olá,
estou tentando gerar Jasper em um applet em uma pagina jsp mas somente aparece uma tela pra salvar o arquivo.
O que busco aparecer o relatorio em applet como fosse JasperViewer mas não aparece …
Alguém poderia me ajudar …
abs
----
public String execute(HttpServletRequest request,HttpServletResponse response) throws Exception{
System.out.println("Wait while loadding Report...");
try{
try{
emf = PersistenceServiceFactory.getInstance().create();
//RuntimeException
}catch (Exception e){
//throw new Exception(01L, "Não conseguiu Conectar no Servidor Banco de Dados.", e, R01Action.class.getCanonicalName(), "execute()");
throw new Exception();
}
manager = emf.createEntityManager();
String host = "http://" + request.getServerName() + ":" + request.getServerPort();
System.out.println("Wait while loadding Report...1");
response.setContentType("application/octet-stream");
String locationImage = request.getContextPath()+ "/imagem/mirax.jpg";
System.out.println("locationImage (host+image)="+host+locationImage);
//trata imagem MANAGER
Session session = (Session) manager.getDelegate();
con = session.connection();
System.out.println("Wait while loadding Report...2");
Map parameters = new HashMap();
System.out.println("Tipo de Grupo = "+request.getParameter("tipo_grupo"));
parameters.put("tipo_grupo", Long.valueOf(request.getParameter("tipo_grupo")));
parameters.put("imagem_dir", host+locationImage);
String jasper = request.getContextPath()+ "/reports/Grupo001.jasper";
@SuppressWarnings("unused")
URL jasperURL = new URL(host + jasper);
System.out.println("Getting the binary..."+jasperURL.getFile());
JasperReport relatoriosJasper = (JasperReport)JRLoader.loadObject(jasperURL);
JasperPrint jasperPrint = JasperFillManager.fillReport(relatoriosJasper, parameters, con);
ServletOutputStream ouputStream = response.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(ouputStream);
oos.writeObject(jasperPrint);
oos.flush();
oos.close();
ouputStream.flush();
ouputStream.close();
request.setAttribute("REPORT_URL", jasperURL);
} catch (Exception ex) {
System.out.println("Erro="+ex);
}finally{
}
return "/pagina/pdf.jsp";
}
---pdf.jsp
<%
String appletWidth = "750";
String appletHeight = "600";
%>
<html>
<head>
<title>Report Viewer</title>
</head>
<body BGCOLOR="#ffffff" LINK="#000099">
<!--"CONVERTED_APPLET"-->
<!-- HTML CONVERTER -->
<SCRIPT LANGUAGE="JavaScript"><!--
var _info = navigator.userAgent;
var _ns = false;
var _ns6 = false;
var _ie = (_info.indexOf("MSIE") > 0 && _info.indexOf("Win") > 0 && _info.indexOf("Windows 3.1") < 0);
//--></SCRIPT>
<COMMENT>
<SCRIPT LANGUAGE="JavaScript1.1"><!--
var _ns = (navigator.appName.indexOf("Netscape") >= 0 && ((_info.indexOf("Win") > 0 && _info.indexOf("Win16") < 0 && java.lang.System.getProperty("os.version").indexOf("3.5") < 0) || (_info.indexOf("Sun") > 0) || (_info.indexOf("Linux") > 0) || (_info.indexOf("AIX") > 0) || (_info.indexOf("OS/2") > 0)));
var _ns6 = ((_ns == true) && (_info.indexOf("Mozilla/5") >= 0));
//--></SCRIPT>
</COMMENT>
<SCRIPT LANGUAGE="JavaScript"><!--
if (_ie == true) document.writeln('<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH="<%= appletWidth %>" HEIGHT="<%= appletHeight %>" codebase="http://java.com/en/download/windows_automatic.jsp"><NOEMBED><XMP>');
else if (_ns == true && _ns6 == false) document.writeln('<EMBED type="application/x-java-applet;version=1.1.2" CODE = "EmbeddedViewerApplet.class" CODEBASE = "applet" ARCHIVE = "jasperreports-3.0.0-applet.jar" WIDTH="<%= appletWidth %>" HEIGHT="<%= appletHeight %>" REPORT_URL = "<%= request.getParameter("REPORT_URL") %>" scriptable=false pluginspage="http://java.com/en/download/windows_automatic.jsp"><NOEMBED><XMP>');
//--></SCRIPT>
<APPLET CODE="EmbeddedViewerApplet.class" CODEBASE="applet" ARCHIVE="jasperreports-3.0.0-applet.jar" WIDTH="<%= appletWidth %>" HEIGHT="<%= appletHeight %>"></XMP>
<PARAM NAME=CODE VALUE="EmbeddedViewerApplet.class">
<PARAM NAME=CODEBASE VALUE="applet">
<PARAM NAME=ARCHIVE VALUE="jasperreports-3.0.0-applet.jar">
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.2.2">
<PARAM NAME="scriptable" VALUE="false">
<PARAM NAME="REPORT_URL" VALUE="<%= request.getParameter("REPORT_URL") %>">
</APPLET>
</NOEMBED>
</EMBED>
</OBJECT>
<!--
<APPLET CODE = "EmbeddedViewerApplet.class" CODEBASE = "applet" ARCHIVE = "jasperreports-0.6.4-applet.jar" WIDTH="<%= appletWidth %>" HEIGHT="<%= appletHeight %>">
<PARAM NAME = "REPORT_URL" VALUE ="<%= request.getParameter("REPORT_URL") %>">
</APPLET>
-->
<!--"END_CONVERTED_APPLET"-->
</body>
</html>
-----EmbeddedViewerApplet.class
public class EmbeddedViewerApplet extends javax.swing.JApplet{
/**
*
*/
private JasperPrint jasperPrint = null;
/** Creates new form AppletViewer */
public EmbeddedViewerApplet(){
initComponents();
}
/**
*
*/
public void init(){
String url = getParameter("REPORT_URL");
if (url != null){
try{
jasperPrint = (JasperPrint)JRLoader.loadObject(new URL(getCodeBase(), url));
if (jasperPrint != null){
JRViewerSimple viewer = new JRViewerSimple(jasperPrint);
this.pnlMain.add(viewer, BorderLayout.CENTER);
}
}catch (Exception e){
StringWriter swriter = new StringWriter();
PrintWriter pwriter = new PrintWriter(swriter);
e.printStackTrace(pwriter);
JOptionPane.showMessageDialog(this, swriter.toString());
}
}
else
{
JOptionPane.showMessageDialog(this, "Source URL not specified");
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {//GEN-BEGIN:initComponents
pnlMain = new javax.swing.JPanel();
pnlMain.setLayout(new java.awt.BorderLayout());
getContentPane().add(pnlMain, java.awt.BorderLayout.CENTER);
}//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel pnlMain;
// End of variables declaration//GEN-END:variables
}