如何在显示pdf上显示特定的消息错误

时间:2016-03-10 17:55:21

标签: html5 spring spring-mvc exception http-headers

我试图用spring显示PDF报告,我终于明白了,但是当我的代码中出现异常或错误时,问题就出现了。在这种情况下,我想在我的应用程序中显示特定的消息。 sping控制器返回一个ResponseEntity,文件为pdf,代码为http status。

我将此控制器称为带有标记

的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
    }

问题是,我如何捕获并向用户显示错误消息?

提前致谢

1 个答案:

答案 0 :(得分:0)

此链接会帮助您displaying error message in login page after login failure

总之,将errorMessage放在请求中并将其放在页面上。