Jump to content
We've recently updated our Privacy Statement, available here ×

JasperViewer not working in client browser


senthilm

Recommended Posts

Hi all,

       I am using jasperserver 3.5.2 CE.  and using reports which deployed in jasperserver from my struts application. When i use jasperviewer it doen't open in client browser. it open in server machine(JBoss + struts).

So i decided to use sample webapp application in jasper reports. (using from Applet).

When i use it in my application i am getting the following error.

/uploads/projects/jasperreports/image/error.bmp

It would be great if anybody help me to solve this problem.

Regards,

Senthilm

 



Post Edited by senthilm at 08/19/2009 05:20
Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

 

The fact that you were trying to launch a Java desktop application such as the JasperViewer from a Struts application means you were not very familiar with how Web applications work.

But then it is good that you found the Web application sample in JasperReports, which is the best starting point in understanding how to use JR in web environment.

 

I'm sure the URL you obfuscated in the screenshot is a valid URL in your Struts appliation. But the question is: what is that URL doing? What is it returning to the client? Do you know? Can we see the source code of you Web page embedding the applet, to see how you configured it? The one containing the APPLET html tag.

 

Thank you,

Teodor

 

Link to comment
Share on other sites

Thank you Teodor, Yes, that is valid URL (ie http://localhost/PrintReport.do )

 In PrintReportAction..\

 

public class PrintReportAction extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm actionForm,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {

  WSClient client = new WSClient(
               request.getSession().getServletContext().getInitParameter("jasperserver_repository_ws_url"),
               "jasperadmin",
               "jasperadmin");
 
  java.util.Map hashMap = new java.util.HashMap();
  JasperPrint jasperPrint = null;
      try {

           hashMap.put( "uri", "/reports/myReports/Bar_chart_details" );
     jasperPrint = client.runReport( "/reports/myReports/Bar_chart_details", hashMap );
   }
  catch (JRException e)
  {
   response.setContentType("text/html");
   PrintWriter out = response.getWriter();
   out.println("<html>");
   out.println("<head>");
   out.println("<title>JasperReports - Web Application Sample</title>");
   out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"../stylesheet.css\" title=\"Style\">");
   out.println("</head>");
  
   out.println("<body bgcolor=\"white\">");

   out.println("<span class=\"bnew\">JasperReports encountered this error :</span>");
   out.println("<pre>");

   e.printStackTrace(out);

   out.println("</pre>");

   out.println("</body>");
   out.println("</html>");

   return null;
  }

  if (jasperPrint != null)
  {
   response.setContentType("application/octet-stream");
   ServletOutputStream ouputStream = response.getOutputStream();
  
   ObjectOutputStream oos = new ObjectOutputStream(ouputStream);
   oos.writeObject(jasperPrint);
   oos.flush();
   oos.close();

   ouputStream.flush();
   ouputStream.close();
  }
  else
  {
   response.setContentType("text/html");
   PrintWriter out = response.getWriter();
   out.println("<html>");
   out.println("<head>");
   out.println("<title>JasperReports - Web Application Sample</title>");
   out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"../stylesheet.css\" title=\"Style\">");
   out.println("</head>");
  
   out.println("<body bgcolor=\"white\">");
 
   out.println("<span class=\"bold\">Empty response.</span>");
 
   out.println("</body>");
   out.println("</html>");
  }
  return null;
 }
}

above is the code in PrintReportAction.

and my jsp is

<APPLET  CODE = "EmbeddedViewerApp15.class" CODEBASE = "http://localhost/images/" WIDTH = "600" HEIGHT = "400">
 <PARAM NAME = ARCHIVE VALUE = "
http://localhost/images/jasperreports-3.5.2-applet.jar,http://localhost/images/commons-logging-1.0.2.jar,http://localhost/images/commons-collections-3.2.jar" >
 <PARAM NAME = CODEBASE VALUE = "
http://localhost" >
    <PARAM NAME="type" VALUE="application/x-java-applet;version=1.2.2">
    <PARAM NAME="scriptable" VALUE="false">
    <PARAM NAME = "REPORT_URL" VALUE ="/PrintReport.do">
</APPLET>

Thanks in advance,

Senthilm

 

Link to comment
Share on other sites

and my EmbeddedViewerApp15 is..

 

public class EmbeddedViewerApp15 extends javax.swing.JApplet
{

 private JasperPrint jasperPrint = null;
 public EmbeddedViewerApp15()
 {
  initComponents();
 }
 public void init()
 {
  String url = getParameter("REPORT_URL");
  System.out.println("==============url  ================= "+url);
  if (url != null)
  {
   try
   {
    //JOptionPane.showMessageDialog(this, url);
    //JOptionPane.showMessageDialog(this, "Hi"+getCodeBase());
    //JOptionPane.showMessageDialog(this, "URL : "+new URL(getCodeBase(), url));

    jasperPrint = (JasperPrint)JRLoader.loadObject(new URL(getCodeBase(), url));
    if (jasperPrint != null)
    {
     JRViewerSimple15 viewer = new JRViewerSimple15(jasperPrint);
     this.pnlMain.add(viewer, BorderLayout.CENTER);
    }
    JOptionPane.showMessageDialog(this, "Hi");
   }
   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");
  }

 }

 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
 
}

 

Link to comment
Share on other sites

Hi,

 

You took this code from our web sample and you modified it to adapt it to your needs.

This is the right way to do it. But you made so many modifications in the first go, that you basically broke it. No wonder it does not work.

There could be no one single problem, but actually 10 or more problems in your current code, ranging from invalid URLs, to problems with the WS call.

 

So I suggest you take your time and debug the whole thing and corrent each problem at a time.

I suggest you start with the clean sample and make only one modification at a time, making sure it did not break the code.

For instance, in our JSP, when we configure the applet, we did not use absolute URLs like you did. We did not specify http://localhost as CODE_BASE parameter. You have to make sure you understand each modification you made and that you tested it separately.

Making 100 modifications and then complaining on the forum it does not work is useless.

 

You should start with our sample and then try to modify servlet URLs to point to your servlet delivering the report. But the first time around, you should not try to get the report from a WS call. You'll do that later when you are already sure the viewer is working with your servlet that delivers a local report.

 

Anyway, what I'm saying is that it is only you who can help you out of this situation.

 

I hope this hepls.

Teodor

 

Link to comment
Share on other sites

  • 3 weeks later...

Yes teodor,

It's working now.. thanks. But one thing regarding this. When i use Jasperviewer report from in API. It contains "Save" button

which gives us to save to the format hwatever we wish(jasperprint,pdf,excel...). But here it doesn't contain "Save" button report.

Is it becaz of written stream in applet? or is there any way to ahieve this "save" button?

 

Thanks and Regards,

senthilm



Post Edited by senthilm at 09/08/2009 07:23
Link to comment
Share on other sites

  • 3 weeks later...

Hi,

 

All the answers you need are waiting for you in the code. Read the source code. After all, it is an open source project.

You'll understand why the button does not appear and how you would make it appear again.

You would probably also understand what are the implications of having the button there. Who would actually do the export. The applet? In such case the applet classpath would have to contain all the export required dependencies such as the iText library and all.

So you might consider exporting on the server, to keep the applet small. So your save button would actually make an URL call to a servlet that performs the export on the server side.

 

So there are many things you need to try out, decide and do yourself. Waiting for all to come from these forums is counter-productive.

 

Thank you,

Teodor

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...