I've been writing a prototype Jersey (JAX-RS) application and wanted to try handling application/x-www-form-urlencoded posts with a redirect-after-POST methodology.
I want to redirect to an html page hosted at the application root on success, however I can't seem to escape out of Jersey's servlet root.
Here's an example of a resource which allows you to create a new user:
URI I want: /jersey-test/user.html
URI I get: /jersey-test/r/user.html
@POST
@Consumes({MediaType.APPLICATION_FORM_URLENCODED})
public Response putUser(@Context UriInfo uriInfo,
MultivaluedMap<String, String> formParams) {
// snip... do work and insert user here...
URI uri = uriInfo.getBaseUriBuilder().path("user.html").build();
return Response.seeOther(uri).build();
}
Relevant snippets from my web.xml:
<web-app ...>
<display-name>jersey-test</display-name>
...
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
...
</servlet>
...
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/r/*</url-pattern>
</servlet-mapping>
</web-app>
Assign the path like this:
URI uri = uriInfo.getBaseUriBuilder().path("../user.html").build();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With