Hi,
I don't use browser in my applications any more but I did that before
with .jasper. Here is the code:
public abstract class PdfServlet extends HttpServlet {
protected Map parameters;
protected File reportFile;
protected ServletContext context;
protected byte[] bytes = null;
public void service( HttpServletRequest request, HttpServletResponse
response )
throws IOException, ServletException {
context = this.getServletConfig().getServletContext();;
try {
execute(request);
} 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;
}
System.out.println("bytes = " + bytes.length);
if (bytes != null && bytes.length > 0) {
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
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>");
}
}
protected abstract void execute( HttpServletRequest request )
throws JRException;
}
public class TitleSummaryReportServlet extends PdfServlet {
protected void execute(HttpServletRequest request) throws
JRException {
reportFile = new
File(context.getRealPath("/WEB-INF/classes/com/web/report/TitleListReport.jasper"));
parameters = new HashMap();
parameters.put("ReportTitle", "Movie Title Summary Report");
parameters.put("BaseDir", reportFile.getParentFile());
bytes = JasperRunManager.runReportToPdf ( reportFile.getPath(),
parameters,
new
TitleListDataSource(request) );
}
}
The idea is to generate a pdf on the server side that shows up in the
browser.
Clifford
Post by mervz22oy,hi tnx for your reply.i really appreciate this information, by
the way i am developing website that used thinlet,i would like to
know if .jrxml file would be possible to view on the web.using
thinlet.
my database is mysql.
http://www.kgo.de/ThinSQL.html
here the thinlet information that im using.
php connection to the mysql database.
i hope you are familiar with this site.
thank very much for your reply.
and i also tried your suggestion.
i hope you will give me some other information to this matter.
thx
------------------------ Yahoo! Groups Sponsor --------------------~-->
Fair play? Video games influencing politics. Click and talk back!
http://us.click.yahoo.com/T8sf5C/tzNLAA/TtwFAA/nhFolB/TM
--------------------------------------------------------------------~->
_________________________________________________________________
Thinlet Project Site | http://thinlet.com
Thinlet Addon Central | http://thinletplus.com
Thinlet World News Blog | http://thinletworld.com
Thinlet F.A.Q. | http://xul.sourceforge.net/thinfaq.html