I would like to have my JAX-RX Application start at the root context so my URLs will be
http://example.com/restfullPath
and not
http://example.com
I have found another solution that involves internal Jersey classes, I assume it's probably just not yet part of the JAX-RS spec. (based on: http://www.lucubratory.eu/simple-jerseyrest-and-jsp-based-web-application/)
web.xml
jersey-rest-jsp-frame-1
jersey
com.sun.jersey.spi.container.servlet.ServletContainer
com.sun.jersey.config.property.JSPTemplatesBasePath
/WEB-INF/jsp
com.sun.jersey.config.property.WebPageContentRegex
(/(image|js|css)/?.*)|(/.*\.jsp)|(/WEB-INF/.*\.jsp)|
(/WEB-INF/.*\.jspf)|(/.*\.html)|(/favicon\.ico)|
(/robots\.txt)
jersey
/*
WEB-INF/jsp/index.jsp
<%@ page contentType="text/html; charset=UTF-8" language="java" %>
Hello ${it.foo}!
IndexModel.java
package example;
import com.sun.jersey.api.view.Viewable;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.net.URI;
import java.util.HashMap;
@Path("/")
@Produces(MediaType.TEXT_HTML)
public class IndexModel {
@GET
public Response root() {
return Response.seeOther(URI.create("/index")).build();
}
@GET
@Path("index")
public Viewable index(@Context HttpServletRequest request) {
HashMap model = new HashMap();
model.put("foo","World");
return new Viewable("/index.jsp", model);
}
}
This seems to work, but I wonder if it is / will be part of JAX-RS spec / implementation.