有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

泽西岛java Show图片例外Apper

我试图为CompletionException编写自定义异常映射程序,并在出现此异常时显示图像。这是我的地图:

@Provider
public class CustomCompleteExceptionManager implements ExceptionMapper<CompletionException> {

    @Override
    public Response toResponse(CompletionException e) {
        return Response
                .status(Response.Status.BAD_REQUEST)
                .entity(Paths.get("error.png").toFile())
                .type("image/img")
                .build();
    }

当我的代码抛出CompletionException,但浏览器不显示error.png时,调用方法toResponse。我得到一个错误:

This site can’t be reached

The webpage at http://localhost:8080/cf/point might be temporarily down or it may have moved permanently to a new web address.

当我只向Response写入字符串消息时,它可以正常工作:

@Provider
public class CustomCompleteExceptionManager implements ExceptionMapper<CompletionException> {

    @Override
    public Response toResponse(CompletionException e) {
        return Response
                .status(Response.Status.BAD_REQUEST)
                .entity(e.getMessage())
                .build();
    }

有什么问题吗


共 (0) 个答案