Welcome page in REST with Java (JAX-RS) using Jersey

jax-rs, jersey, rest

Solution

I found an alternative way to do this. instead of using index.jsp, I can use a class like:

@Path("/")
public class Hello {

    // This method is called if HTML is request
    @GET
    @Produces(MediaType.TEXT_HTML)
    public String sayHtmlHello() {
       return "<html> " + "<title>" + "Rest Page" + "</title>"
          + "<body><h1>" + "REST is Working!" + "</body></h1>" + "</html> ";
}

In web.xml I do not need to use:

<welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

And it works fine with:

<url-pattern>/*</url-pattern>

Problem

I am implementing a Restful Web Service using Jersey. I want to show index.jsp as welcome page. ``` <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Rest Page</title> </head> <body> <h1>Rest is working!</h1> </body> </html> ``` It works fine when I use this code in my web.xml: ``` <servlet-mapping> <servlet-name>Jersey REST Service</servlet-name> <url-pattern>/whatever/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> ``` The problem is when the user-pattern is like this: ``` <url-pattern>/*</url-pattern> ``` Everything works fine except welcome page. I appreciate Any help.

Original source