【问题标题】:how to show a especific message error on display pdf如何在显示pdf上显示特定消息错误
【发布时间】: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


    【解决方案1】:

    这个链接对你有帮助吗,displaying error message in login page after login failure

    总之,将 errorMessage 放入请求中并在您的页面上获取。

    【讨论】:

    • 它对我不起作用。我需要在我的模板中捕获响应,但对象响应在那里不可用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    • 2021-12-02
    相关资源
    最近更新 更多