我的 Web 应用程序使用 JASPERREPORTS 来编译和提供各种报告。报告中出现的所有图像均来自 ImageServlet net.sf.jasperreports.j2ee.servlets.ImageServlet
。
<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>/image</url-pattern>
</servlet-mapping>
对图像的请求是这样的:
GET /watapp/image?rand=0.5039537955900038&image=px
在我的应用程序的安全审计中,有人提出如果查询参数被更改,例如设置 image=pxxx
会导致 500 内部服务器错误。所以我需要处理这个异常。
net.sf.jasperreports.engine.JRRuntimeException: Invalid image name: pxxx
at net.sf.jasperreports.engine.export.JRHtmlExporter.getPrintElementIndex(JRHtmlExporter.java:2408)
at net.sf.jasperreports.engine.export.JRHtmlExporter.getImage(JRHtmlExporter.java:695)
at net.sf.jasperreports.j2ee.servlets.ImageServlet.service(ImageServlet.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.watapp.filters.login.ApplicationFilter.doFilter(ApplicationFilter.java:41)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
我的问题是,如何处理这个异常?servlet 与 JASPER jar 一起提供,我无法控制 servlet 的代码。请指教。