• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts 2.2.3 jasper ImageServlet problem

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using the jasper reports plugin for Struts 2.2.3 and whenever I try to generate a HTML formatted report, all the images are broken. What appears to be the problem is the ImageServlet class that responds to image requests is not being called. Here is the relevant code:

web.xml
<servlet>
<servlet-name>ImageServlet</servlet-name>
<servlet-class>net.sf.jasperreports.j2ee.servlets.ImageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ImageServlet</servlet-name>
<url-pattern>/servlets/image</url-pattern>
</servlet-mapping>

Struts.xml
<result name="html" type="jasper">
.
.
<param name="imageServletUrl">/servlets/image?image=</param>
</result>

This a sample line from the broken image html report that was displayed

<td><img alt="" src="/toga_reports/servlets/image?image=px" style="width: 21px; height: 1px;"/></td>

The reason why I believe the ImageServlet isn't being called is I added the .java source code for that class in Eclipse and set a breakpoint at the beginning of the service method. When the code ran, the breakpoint was never reached.

Does anyone understand why the ImageServlet isn't being called based on my configuation? Any help is GREATLY appreciated
 
V. Oliver Smith
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After much labor, I figured out what the issue was. The problem is the StrutsPrepareAndExecuteFilter that is configured in web.xml intercepts every URL request made to my app. In the case of the ImageServlet, since it was configured in web.xml as well, this is undesired behavior as it would never be called.

The solution was to add the following in my struts.xml file:

<constant name="struts.action.excludePattern" value="/servlets/image*"/>

This causes the Struts Filter Dispatcher class to ignore URLs that match the pattern and allows the ImageServlet to handle those requests instead.
 
reply
    Bookmark Topic Watch Topic
  • New Topic