Can not connect JAX-RS service to MVC template

后端 未结 4 386
抹茶落季
抹茶落季 2021-01-02 20:22

I\'m attempting to make use of JAX-RS\' (Jersey) MVC pattern. Attempts to reach http://localhost:8080/myproject/foos/test result in an error that reads:

jav         


        
4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-02 21:21

    Made the following changes:

    web.xml:

    
    
        
            30
        
    
        
            welcome.jsp
        
    
        
            jersey
            com.sun.jersey.spi.container.servlet.ServletContainer
            
                com.sun.jersey.config.property.packages
                controllers
                    
            
                com.sun.jersey.config.property.WebPageContentRegex
                /((WEB-INF/views))/.*
            
            
                com.sun.jersey.config.property.JSPTemplatesBasePath
                /WEB-INF/views/
            
            
                com.sun.jersey.config.feature.Redirect
                true
            
            
                com.sun.jersey.config.feature.FilterForwardOn404
                true
                    
        
        
            jersey
            /*
        
    
    
    

    Resource:

    @Path("foos")
    public class FooResource {
    
        @GET
        @Produces(MediaType.TEXT_HTML)
        public Viewable index() {
    
            return new Viewable("/foos/index", this);
    
        }   
    
        @GET
        @Path("{id}")
        @Produces(MediaType.TEXT_HTML)
        public Viewable view(@PathParam("id") String id) {
    
            return new Viewable("/foos/view", id);
    
        } 
    
    }
    

    Views:

    • \welcome.jsp
    • \WEB-INF\views\foos\
      • index.jsp
      • view.jsp

提交回复
热议问题