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

前端 未结 2 600
离开以前
离开以前 2021-01-14 06:18

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\"%&         


        
相关标签:
2条回答
  • 2021-01-14 06:55

    Well servlet mapping calls your servlet. If you want to create a homepage then you should not give /* to the servlet because it will overlap.

    When your url pattern is /whateveryour servlet will run under localhost:8080/myApp/whatever and and homepage will have Localhost:8080/myApp. However whn you define your url pattern as /* both your servlet and home page have tha same place. So remove your servlet mapping or give it a different place other than /*

    0 讨论(0)
  • 2021-01-14 07:01

    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>
    
    0 讨论(0)
提交回复
热议问题