java - Show jasper report HTML page (web app) in Spring roo aplication -


i'm novice spring roo.

with spring roo created application. when use webapp example in spring roo results pdf, word, .... html , "html page page viewer" not work. when change html , "html page page viewer" hello world, appear correct. jsp pages correctly declared. further not error.

with webapp example code of jasperreports library outside of spring roo application desired results, when use same jsp file in spring roo application empty screen.

in jsp check jasperprint object not empty , can see has 10 pages. system.out.println("aantal pagina's = " + jasperprint.getpages().size());

in fileuploadcontroller set session attributes. start message.jsp file. message.jsp file export page in jasperreports webapp example. message.jsp file show correctly. also, pdf, word etc. links work correctly , see correct pdf representation of jasper report. first 2 links, html , html viewer page page not show correctly. html page empty. when change page "hello world" shows correctly.

in spring roo have fileupload entity. in fileuploadcontroller added:

 @requestmapping(method = requestmethod.post, produces = "text/html")  public string create(@valid fileupload fileupload, bindingresult bindingresult, model uimodel, httpservletrequest httpservletrequest) throws urlnotfoundexception {     if (bindingresult.haserrors()) {         populateeditform(uimodel, fileupload);         return "fileuploads/create";     }      file file = null;     uimodel.asmap().clear();     commonsmultipartfile image = fileupload.getimage();     if (image != null) {         file = new file(image.getoriginalfilename());         system.out.println("original filename = " + image.getoriginalfilename());         try {             image.transferto(file);             fileupload.setcontenttype(image.getcontenttype());             fileupload.setpath(file.getabsolutepath());             fileupload.setremoteurl(httpservletrequest.getremoteaddr());         } catch (exception e) {             e.printstacktrace();             return "fileuploads/create";         }     }      file jrprintfile = file;      jasperprint jasperprint = null;     try {         jasperprint = (jasperprint)jrloader.loadobject(jrprintfile);     } catch (jrexception e) {         // todo auto-generated catch block         e.printstacktrace();     }      httpservletrequest.getsession().setattribute(basehttpservlet.default_jasper_print_session_attribute, jasperprint);     httpservletrequest.getsession().setattribute(imageservlet.default_jasper_print_session_attribute, jasperprint);      httpservletrequest.setattribute("filepath", file.getabsolutepath());     httpservletrequest.setattribute("message", "the report " + image.getoriginalfilename() + "has been done successfully!");      fileupload.persist();     return "fileuploads/message";     //  return "redirect:/fileuploads/" + encodeurlpathsegment(fileupload.getid().tostring(), httpservletrequest);  }  } 

my message.jsp file (like export page in jasperreports webapp example)

      <%@ page language="java" contenttype="text/html; charset=iso-8859-1"          pageencoding="iso-8859-1" import="java.util.date"%>       <!doctype html public "-//w3c//dtd html 4.01 transitional//en"          "http://www.w3.org/tr/html4/loose.dtd">       <html>             <h3>html viewers</h3>             <ul>                <li><a href="jasperhtmlview" target="_blank"><span class="desc">html                   viewer</span></a>                </li>                <li><a href="jasperviewer" target="_blank"><span class="desc">html                   page page viewer</span></a>                </li>             </ul>             <h3>pdf viewer</h3>             <h3>                <span class="desc"></span>             </h3>             <ul>                <li><a href="servlets/pdf" target="_blank"><span class="desc">pdf                   export</span></a>                </li>             </ul>             <h3>office&nbsp; viewers</h3>             <ul>                <li><a href="servlets/docx" target="_blank"><span                   class="desc">word (docx)</span></a></li>                <li><a href="servlets/xlsx" target="_blank"><span                   class="desc">excel (xlsx)</span></a></li>                <li><a href="servlets/xls" target="_blank"><span class="desc">excel                   2003(xls)</span></a>                </li>                <li><a href="servlets/pptx" target="_blank"><span                   class="desc">powerpoint (pptx)</span></a></li>                <li><a href="servlets/odt" target="_blank"><span class="desc">pendocument                   text (odt)</span></a>                </li>                <li><a href="servlets/ods" target="_blank"><span class="desc">opendocument                   spreadsheet (ods)</span></a>                </li>             </ul>             <%                date created = new date(session.getcreationtime());                date accessed = new date(session.getlastaccessedtime());                date expiry = new date(session.getlastaccessedtime()                + session.getmaxinactiveinterval() * 1000);                %>             <footer>                <hr>                <table style="width: 100%" border="0">                   <tbody>                      <tr>                         <td>                            <pre>session id</pre>                         </td>                         <td><%=session.getid()%></td>                         <td>method</td>                         <td><%=request.getmethod()%></td>                      </tr>                      <tr>                         <td>created</td>                         <td><%=created%></td>                         <td>request uri</td>                         <td><%=request.getrequesturi()%></td>                      </tr>                      <tr>                         <td>last accessed</td>                         <td><%=accessed%></td>                         <td>path info</td>                         <td><%=request.getpathinfo()%></td>                      </tr>                      <tr>                         <td>next expired time</td>                         <td><%=expiry%></td>                         <td>remote address</td>                         <td><%=request.getremoteaddr()%></td>                      </tr>                   </tbody>                </table>                <hr>             </footer>          </body>       </html> 

my code in html.jsp lookes like:

 <%@ page errorpage="error.jsp" %>  <%@ page import="net.sf.jasperreports.engine.*" %>  <%@ page import="net.sf.jasperreports.engine.*" %>  <%@ page import="net.sf.jasperreports.engine.util.*" %>  <%@ page import="net.sf.jasperreports.engine.export.*" %>  <%@ page import="net.sf.jasperreports.j2ee.servlets.*" %>  <%@ page import="java.util.*" %>  <%@ page import="java.io.*" %>   <%     jasperprint jasperprint = (jasperprint) session.getattribute(imageservlet.default_jasper_print_session_attribute);      if (jasperprint == null) {         throw new jrruntimeexception("file webappreport.jrprint not found.");     }     system.out.println("jasper print object not null");     system.out.println("aantal pagina's = " + jasperprint.getpages().size());      session.setattribute(imageservlet.default_jasper_print_session_attribute, jasperprint);      htmlexporter exporter = new htmlexporter();      //  session.setattribute(basehttpservlet.default_jasper_print_session_attribute, jasperprint);      exporter.setparameter(jrexporterparameter.jasper_print, jasperprint);     exporter.setparameter(jrexporterparameter.output_writer, out);     //  exporter.setparameter(jrhtmlexporterparameter.images_uri, "../servlets/image?image=");     exporter.setparameter(jrhtmlexporterparameter.images_uri, "./servlets/image?image=");      exporter.exportreport();  %> 

you can try using gvnix framework (based on spring-roo) implements functionalities works jasper reports , other interesting functionalities.

visit following links learn more gvnix framework:

http://github.com/disid/gvnix http://code.google.com/p/gvnix/

and here have example how implement application jasper reports using gvnix:

http://github.com/disid/gvnix-samples/tree/master/quickstart-app#reports

best regards,


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -