Welcome file not working with html file in spring

前端 未结 6 1190
难免孤独
难免孤独 2020-12-19 10:09

I have given my welcome file in web.xml But when running the application, it is showing 404 error on http://172.16.2.16:8080/sampletest/

It is a spring

6条回答
  •  情深已故
    2020-12-19 10:10

    Welcome file can be access using following changes.

    change 1. add resource path in dispatcher as following :

          
    

    change 2. add controller handler like following :

         @Controller
          public class RestController {
    
         @RequestMapping(value = "/", method = RequestMethod.GET)
          public String welcome() {
                return "index.html";
          }
    
         }
    

    changes 3: index.html file should be in WebContent folder in project.

    Note : If you are not able to add mvc bean in dispatcher servlet file then add

      xmlns:mvc="http://www.springframework.org/schema/mvc
    

    in dispatcher servlet config file.

提交回复
热议问题