Integrating iReport into Thinwire should not be a problem.
First generate the report on the server from any Thinwire class and save the pdf so it accessable from the browser ( This could be in your Thinwire app or in ROOT folder of tomcat)
Open a window with the link with Hyperlink.openLocation
Hope this helps
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I did a similar thing for any file download. Create a delegate server, its in the forums somewhere. Listen for for a method get, with a parameter that you define. You will want a static Hashmap to map a resource name to a filename.
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
StaticHashmap.remove(resourcename);
response.getOutputStream().write(fileByteArray);
response.flushBuffer();
return; //you don't want to delegate this response
}
}
}
thinwireServlet.service(request, response);
}
then open a hyperlink location when u wish the client to recieve a file
StaticHashmap.put(resourcename,filename);
Hyperlink.openLocation("?_filedownload_=" + resourcename);
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I use it in TomCat with ThinWire on regular basis to deliver Jasper reports, all works Ok, as expected (and how it is specified in Servlet Specification, v.2.4).
May you say more exact what and how it is not working in your opinion?
You say " it just redirects to the servlet", but it is exactly what it has to do - it maps URL to the servlet and then servlet decides how to process that URL.
I found the same problem when the servlet mapping in web.xml is not in the correct order.
Note Oleksandr's web.xml file:
<servlet-mapping>
<servlet-name>ReportsServlet</servlet-name>
<url-pattern>/Reports/*</url-pattern>
<!-- Alternatively *.pdf may be used as pattern -->
</servlet-mapping>
According to Servlet Specification 2.4 order of mappings should not matter - the most specific mapping shall be used. It, definitely, does not preclude specific servlet container to be buggy, but ... I just have tested - with Tomcat 5.5.20 it really does not matter, if I swap mappings, application behavior is not affected.
Here is quotation from Servlet Specification 2.4 (chapter 11.1)
-----------------------------------------------------------------
1. The container will try to find an exact match of the path of the request to the
path of the servlet. A successful match selects the servlet.
2. The container will recursively try to match the longest path-prefix. This is done
by stepping down the path tree a directory at a time, using the ’/’ character as
a path separator. The longest match determines the servlet selected.
1. Previous versions of this specification made use of these mapping techniques
as a suggestion rather than a requirement, allowing servlet containers
to each have their different schemes for mapping client requests
to servlets.
MAPPING REQUESTS TO SERVLETS
Final Version
86
3. If the last segment in the URL path contains an extension (e.g. .jsp), the servlet
container will try to match a servlet that handles requests for the extension.
An extension is defined as the part of the last segment after the last ’.’ character.
4. If neither of the previous three rules result in a servlet match, the container will
attempt to serve content appropriate for the resource requested. If a "default"
servlet is defined for the application, it will be used.
-----------------------------------------------------------------
Regards,
Oleksandr
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When I access two servlet using different url respectively in the brower which is opened by myself, that's ok, that is to say, i can get what i want. But if i click a hyperlink in a window located by one url to open a new window which accesses another url, it will redirect to the former url. I don't konw why. Who can give me some explanations?
Melvin
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Greetings people
Do you have a html invocation of a report example using the iReport and ThinWire frameworks?
I need to launch a report and download the pdf version in my browser.
Please, help me folks!
Best regards
From Manta, Ecuador
Carlos Julio Pérez
Integrating iReport into Thinwire should not be a problem.
First generate the report on the server from any Thinwire class and save the pdf so it accessable from the browser ( This could be in your Thinwire app or in ROOT folder of tomcat)
Open a window with the link with Hyperlink.openLocation
Hope this helps
Somebody has an example?
I can't open the pdf file in my browser (opera and/or firefox)
Thanks for your help
Best regards
Alternatively use a report servlet that streams the PDF to the browser.
I have an example but I used jasperreports on servlet doPost:
lines = (Vector<DebtorStatementLineBean>) db.getDebtorTransactions(
"F101S", (Date) df.parseObject("2005/06/21"), (Date) df
.parseObject("2005/07/01"));
JRBeanCollectionDataSource source = new JRBeanCollectionDataSource(
lines);
String realPath = request.getSession().getServletContext().getRealPath(
"/");
ServletOutputStream servletOutputStream = response.getOutputStream();
//GENERATE REPORT
File reportFile = new File(getServletConfig().getServletContext()
.getRealPath("/reports/drStatement.jasper"));
byte[] bytes = null;
String report = null;
// Save Report TO PDF Byte array
bytes = JasperRunManager.runReportToPdf(reportFile.getPath(),
new HashMap(), source);
// Setup response as pdf
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
// Bytes written to servlet output stream
servletOutputStream.write(bytes, 0, bytes.length);
servletOutputStream.flush();
servletOutputStream.close();
Hi Pieter
Thanks for your code example. But, i have a little question about it too.
How do you integrate your report example code with thinwire?
How do you invoke servlet's request() method or servlet' session object in thinwire?
Do you can help me with more code please?
PD: Sorry by my english, i speak spanish.
Best regards from Ecuador
I did a similar thing for any file download. Create a delegate server, its in the forums somewhere. Listen for for a method get, with a parameter that you define. You will want a static Hashmap to map a resource name to a filename.
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
String method = request.getMethod();
if (method.equals("GET")) {
String resource = request.getParameter("_filedownload_");
if(resource != null){
try {
String mime = getServletContext().getMimeType(resourceName.toLowerCase());
response.setContentType(mime);
response.setHeader("Content-Disposition","filename="+StaticHashmap.get(resourcename));
StaticHashmap.remove(resourcename);
response.getOutputStream().write(fileByteArray);
response.flushBuffer();
return; //you don't want to delegate this response
}
}
}
thinwireServlet.service(request, response);
}
then open a hyperlink location when u wish the client to recieve a file
StaticHashmap.put(resourcename,filename);
Hyperlink.openLocation("?_filedownload_=" + resourcename);
In this specific case all can be done much simplier -
just define in your web.xml 2 servlets and, correspondingly, 2 mappings, e.g.
<servlet>
<description>
Servlet to sproduce reports
</description>
<display-name>Reports Servlet</display-name>
<servlet-name>ReportsServlet</servlet-name>
<servlet-class>some.pakage.ReportsServlet</servlet-class>
</servlet>
<servlet>
<description>
Web Servlet
</description>
<display-name>TW Application Servlet</display-name>
<servlet-name>WebServlet</servlet-name>
<servlet-class>thinwire.render.web.WebServlet</servlet-class>
... Usual TninWire bla-bla-bla ...
</servlet>
<servlet-mapping>
<servlet-name>ReportsServlet</servlet-name>
<url-pattern>/Reports/*</url-pattern>
<!-- Alternatively *.pdf may be used as pattern -->
</servlet-mapping>
<servlet-mapping>
<servlet-name>WebServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
No delegating is required
Regards,
Oleksandr
That URL mapping thing doesn't work for me in tomcat, it just redirects to the servlet.
H-m-m,
I use it in TomCat with ThinWire on regular basis to deliver Jasper reports, all works Ok, as expected (and how it is specified in Servlet Specification, v.2.4).
May you say more exact what and how it is not working in your opinion?
You say " it just redirects to the servlet", but it is exactly what it has to do - it maps URL to the servlet and then servlet decides how to process that URL.
In my example any URL that starts with http://host:port/MyTWApplication/Reports/ will be processed by ReportsServlet (i.e. report will be generated and returned), and any other URL that starts with http://host:port/MyTWApplication/ will be processed by ThinWire.
Regards,
Oleksandr
I found the same problem when the servlet mapping in web.xml is not in the correct order.
Note Oleksandr's web.xml file:
<servlet-mapping>
<servlet-name>ReportsServlet</servlet-name>
<url-pattern>/Reports/*</url-pattern>
<!-- Alternatively *.pdf may be used as pattern -->
</servlet-mapping>
<servlet-mapping>
<servlet-name>WebServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
The ReportsServlet mapping must be before the WebServlet otherwise if you try to get to the Reports servlet it will go to the WebServlet instead.
Pieter
According to Servlet Specification 2.4 order of mappings should not matter - the most specific mapping shall be used. It, definitely, does not preclude specific servlet container to be buggy, but ... I just have tested - with Tomcat 5.5.20 it really does not matter, if I swap mappings, application behavior is not affected.
Here is quotation from Servlet Specification 2.4 (chapter 11.1)
-----------------------------------------------------------------
1. The container will try to find an exact match of the path of the request to the
path of the servlet. A successful match selects the servlet.
2. The container will recursively try to match the longest path-prefix. This is done
by stepping down the path tree a directory at a time, using the ’/’ character as
a path separator. The longest match determines the servlet selected.
1. Previous versions of this specification made use of these mapping techniques
as a suggestion rather than a requirement, allowing servlet containers
to each have their different schemes for mapping client requests
to servlets.
MAPPING REQUESTS TO SERVLETS
Final Version
86
3. If the last segment in the URL path contains an extension (e.g. .jsp), the servlet
container will try to match a servlet that handles requests for the extension.
An extension is defined as the part of the last segment after the last ’.’ character.
4. If neither of the previous three rules result in a servlet match, the container will
attempt to serve content appropriate for the resource requested. If a "default"
servlet is defined for the application, it will be used.
-----------------------------------------------------------------
Regards,
Oleksandr
try this site.there is a module that produce report,http://www.cs-solutions.info:8080/cmis/
When I access two servlet using different url respectively in the brower which is opened by myself, that's ok, that is to say, i can get what i want. But if i click a hyperlink in a window located by one url to open a new window which accesses another url, it will redirect to the former url. I don't konw why. Who can give me some explanations?
Melvin