users@jersey.java.net

[Jersey] how to redirect response to another JSP file?

From: joey.lv <joey.lv_at_7road.com>
Date: Wed, 7 May 2014 17:29:30 +0800

Hi, all

Jersey 2.7/2.8

My Restful method, in this method, I want to redirect response to index.jsp, I tried response.seeOther(location) and response.temporaryRedirect(location), none of these worked, the client Status Code is: 204 No Content.

At last I tried this code: throw new WebApplicationException(response.temporaryRedirect(location).build()), It worked, the client Status Code is : 307 Temporary Redirect.

So, is there any other way to redirect response to another JSP file?


@GET
@Path("/getLogin")
@Produces(MediaType.TEXT_PLAIN)
public void getLogin(@QueryParam("account") String account,
                       @QueryParam("account") String password,
                       @Context UriInfo uriInfo,
                       @Context Response response) {

    //Something will be done here

    try {
        java.net.URI location = new java.net.URI("http://localhost:8080/index.jsp");
        //response.seeOther(location); //not work
        //response.temporaryRedirect(location); //not work
        //throw new WebApplicationException(response.temporaryRedirect(location).build()); // it work
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}