【发布时间】:2016-03-10 17:55:21
【问题描述】:
我正在尝试使用 spring 显示报告 PDF,我终于得到了它,但是当我的代码中有异常或错误时,就会出现问题。在这种情况下,我想在我的应用程序中显示特定的消息。 sping控制器返回一个带有pdf文件的ResponseEntity,以及一个http状态码。
我把这个控制器称为我的带有标签的html模板
<div role="tabpanel" class="tab-pane" id="co_<%= idFacturaF1 %>">
<object class="pdfObject" data="<%= App.CONTEXT_PATH + '/api/certificadoOrigen/' + idFacturaF1%>#page=1&view=FitH,top" type="application/pdf">
<param name="wmode" value="transparent">
<param name="allowfullscreen" value="true" />
alt : <a href="<%= App.CONTEXT_PATH + '/api/certificadoOrigen/' + idFacturaF1%>">CO.pdf</a>
</object>
</div>
这是控制器:
@RequestMapping(value = "/api/certificadoOrigen/{id}", method = RequestMethod.GET, produces = "application/pdf")
public Object getPDFCo(final @PathVariable("id") Long id, final HttpServletRequest request) {
try {
// sentences where build the pdf object...
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.put("Content-Type", Arrays.asList(new String[] { "application/pdf;charset=UTF-8" }));
final ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(pdf, httpHeaders, HttpStatus.OK);
return response;
} catch (final Exception e) {
//Here I want to capture the message errors
}
问题是,如何捕获错误消息并将其显示给用户?
提前致谢
【问题讨论】:
标签: html spring spring-mvc exception http-headers