【问题标题】:How to redirect to html page with RESTEasy? [duplicate]如何使用 RESTEasy 重定向到 html 页面? [复制]
【发布时间】:2017-12-21 08:55:39
【问题描述】:

我用的是RESTEasy 3.1.4-Final,我有一个方法:

    @GET
    @Produces(MediaType.TEXT_HTML)
    public Response getInteractionsData(@Context UriInfo ui) {
        return Response.ok().entity("index.html").build();
    }

如何重定向到 index.html?现在我得到一个纯文本“index.html”(带有响应标题文本/html)。 另见https://docs.oracle.com/cd/E19776-01/820-4867/ghrpv/

在我为此目标使用 Servlet API 之前:

        RequestDispatcher dispatcher = request.getRequestDispatcher("index.html");
        if (dispatcher != null) {
            dispatcher.forward(request, response);
        }

但现在我不能有 requestresponse。对不起我的英语不好

【问题讨论】:

    标签: java html redirect resteasy


    【解决方案1】:

    看看这篇文章的答案

    Redirect from JAX-RS

    Response.temporaryRedirect(URI)
    

    Response.seeOther(URI)
    

    “临时重定向”返回 307 状态码,而“查看其他”返回 303。

    【讨论】:

    • 谢谢!你能告诉我 index.html 文件应该放在哪里吗?
    • 如果不查看您的精确设置,我很难说出来,但是您在运行上述代码时观察到的任何异常都应该给您一个线索
    猜你喜欢
    • 2013-02-14
    • 1970-01-01
    • 2012-06-18
    • 1970-01-01
    • 1970-01-01
    • 2019-10-28
    • 1970-01-01
    • 2016-09-16
    • 2011-01-13
    相关资源
    最近更新 更多