|
1 | 1 | /* |
2 | | - * $Id$ |
3 | | - * |
4 | 2 | * Licensed to the Apache Software Foundation (ASF) under one |
5 | 3 | * or more contributor license agreements. See the NOTICE file |
6 | 4 | * distributed with this work for additional information |
|
18 | 16 | * specific language governing permissions and limitations |
19 | 17 | * under the License. |
20 | 18 | */ |
21 | | - |
22 | 19 | package org.apache.struts2.views.jasperreports; |
23 | 20 |
|
24 | 21 | import com.netsteadfast.greenstep.base.Constants; |
@@ -289,7 +286,7 @@ protected void doExecute(String finalLocation, ActionInvocation invocation) thro |
289 | 286 | // TODO 更改 systemId 的位址 |
290 | 287 | if (Constants.JASPER_REPORTS_RESULT_LOCATION_REPLACE_MODE) { |
291 | 288 | systemId = finalLocation; |
292 | | - } |
| 289 | + } |
293 | 290 |
|
294 | 291 | Map parameters = new ValueStackShadowMap(stack); |
295 | 292 | File directory = new File(systemId.substring(0, systemId.lastIndexOf(File.separator))); |
@@ -361,7 +358,7 @@ protected void doExecute(String finalLocation, ActionInvocation invocation) thro |
361 | 358 |
|
362 | 359 | Map imagesMap = new HashMap(); |
363 | 360 | request.getSession(true).setAttribute("IMAGES_MAP", imagesMap); |
364 | | - |
| 361 | + |
365 | 362 | // TODO : 改為jasperreport-6.5.1 版本使用的HtmlExporter , 原本: exporter = new JRHtmlExporter(); |
366 | 363 | exporter = new HtmlExporter(); |
367 | 364 | exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap); |
@@ -395,7 +392,10 @@ protected void doExecute(String finalLocation, ActionInvocation invocation) thro |
395 | 392 | throw new ServletException(e.getMessage(), e); |
396 | 393 | } finally { |
397 | 394 | try { |
398 | | - conn.close(); |
| 395 | + if (conn != null) { |
| 396 | + // avoid NPE if connection was not used for the report |
| 397 | + conn.close(); |
| 398 | + } |
399 | 399 | } catch (Exception e) { |
400 | 400 | LOG.warn("Could not close db connection properly", e); |
401 | 401 | } |
|
0 commit comments