Search code examples
javahtmlhttp-redirectresteasy

How to redirect to html page with RESTEasy?


I use RESTEasy 3.1.4-Final, and I have a method:

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

How to redirect to index.html? Now I get a plain text "index.html" (with response header text/html). See also https://docs.oracle.com/cd/E19776-01/820-4867/ghrpv/

Before I used Servlet API for this target:

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

But now i can't have request or response. Sorry for my bad English


Solution

  • Take a look at the answers to this post

    Redirect from JAX-RS

    Response.temporaryRedirect(URI)
    

    OR

    Response.seeOther(URI)
    

    "Temporary Redirect" returns a 307 status code while "See Other" returns 303.