Creating Reports with iReports and JasperReports
June 23, 2005
Setting up the Webapp
Now that we have a report to serve and a database set up to populate our report with data, we just need a web component to serve up the report. That component will be a servlet, so we'll also need a web.xml file so Tomcat will know which requests should be handled by the servlet.
The document below is the web.xml file for the sample application. It is fairly straightforward:
- it describes the servlet that will be serving the report; we will visit this servlet in more detail in the next section
- it maps that servlet to handle requests coming to the /ReportEngine path; this could be a regular expression, but we have no need of such complications for this application
- it sets sessions to time out after 30 minutes
- it tells the servlet container to use welcome.html as the default page for this webapp's virtual directory
- it references the jdbc/jasper_example JNDI resource we defined in the previous section
01 <?xml version="1.0" encoding="ISO-8859-1"?>
02 <!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 03 'http://java.sun.com/dtd/web-app_2_3.dtd'>
04 <web-app id="AgreeMgtSys_WebApp">
05 <display-name>jasper_example WAR</display-name>
06 <description>WAR file containing all web pages and servlets.</description>
07 <servlet>
08 <servlet-name>ReportEngine</servlet-name>
09 <display-name>Report Engine</display-name>
10 <description>The servlet that handles requests to display a 11 Jasper report.</description>
12 <servlet-class>com.skillfusion.articles.jasper.ReportEngine</servlet-class>
13 </servlet>
14 <servlet-mapping>
15 <servlet-name>ReportEngine</servlet-name>
16 <url-pattern>/ReportEngine</url-pattern>
17 </servlet-mapping>
18 <session-config>
19 <session-timeout>30</session-timeout>
20 </session-config>
21 <welcome-file-list>
22 <welcome-file>default.html</welcome-file>
23 </welcome-file-list>
24 <resource-ref>
25 <description>DB Connection</description>
26 <res-ref-name>jdbc/jasper_example</res-ref-name>
27 <res-type>javax.sql.DataSource</res-type>
28 <res-auth>Container</res-auth>
29 </resource-ref>
30 </web-app>
02 <!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 03 'http://java.sun.com/dtd/web-app_2_3.dtd'>
04 <web-app id="AgreeMgtSys_WebApp">
05 <display-name>jasper_example WAR</display-name>
06 <description>WAR file containing all web pages and servlets.</description>
07 <servlet>
08 <servlet-name>ReportEngine</servlet-name>
09 <display-name>Report Engine</display-name>
10 <description>The servlet that handles requests to display a 11 Jasper report.</description>
12 <servlet-class>com.skillfusion.articles.jasper.ReportEngine</servlet-class>
13 </servlet>
14 <servlet-mapping>
15 <servlet-name>ReportEngine</servlet-name>
16 <url-pattern>/ReportEngine</url-pattern>
17 </servlet-mapping>
18 <session-config>
19 <session-timeout>30</session-timeout>
20 </session-config>
21 <welcome-file-list>
22 <welcome-file>default.html</welcome-file>
23 </welcome-file-list>
24 <resource-ref>
25 <description>DB Connection</description>
26 <res-ref-name>jdbc/jasper_example</res-ref-name>
27 <res-type>javax.sql.DataSource</res-type>
28 <res-auth>Container</res-auth>
29 </resource-ref>
30 </web-app>
Now that we've got the webapp set up properly, let's see how the servlet is actually performing its task.

