The origin server did not find a current representation for the target resource or is not willing to disclose that one exists

前端 未结 13 1528
野趣味
野趣味 2020-12-03 00:02

web.xml

    
     

        
13条回答
  •  悲&欢浪女
    2020-12-03 00:43

    the problem is in url pattern of servlet-mapping.

     /DispatcherServlet
    

    let's say our controller is

    @Controller
    public class HomeController {
        @RequestMapping("/home")
        public String home(){
            return "home";
        }
    }
    

    when we hit some URL on our browser. the dispatcher servlet will try to map this url.

    the url pattern of our serlvet currently is /Dispatcher which means resources are served from {contextpath}/Dispatcher

    but when we request http://localhost:8080/home we are actually asking resources from / which is not available. so either we need to say dispatcher servlet to serve from / by doing

    /
    

    our make it serve from /Dispatcher by doing /Dispatcher/*

    E.g

    
    
      springsecuritydemo
    
      
        
        offers
        offers
        org.springframework.web.servlet.DispatcherServlet
        1
      
      
        offers
        /Dispatcher/*
      
    
    
    

    and request it with http://localhost:8080/Dispatcher/home or put just / to request like

    http://localhost:8080/home
    

提交回复
热议问题