Solution to report 404 when SpringMVC project visits controller

  • 2021-11-10 09:27:26
  • OfStack

Directory SpringMVC Visit controller Report 404 Search on the Internet All kinds of methods have not been solved. Finally, the possible reasons why SpringMVC cannot access controller are solved. Look up the information from the Internet

Report when SpringMVC accesses controller 404

I wrote SpringMVC project, suddenly found access to controller path when the page display 404, see the console did not report serious errors, just said that the path can not be found, and a separate access to jsp can also be accessed normally.

The console reports this error

No mapping found for HTTP request with URI [/SpringWebScoket/user/login] in

Search all kinds of methods on the Internet have not been solved

First list the various methods found under 1

1. Check whether the url path is written correctly. Sometimes, the letters may be written backwards, which leads to the wrong path and cannot be found. 2. Is MVC filtering correct

<servlet-mapping>
    <servlet-name>springMVC</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

Some friends say this configuration is "/", some friends say it is "/*". I don't know which one is correct, so I can try it all.

3, static configuration, see some friends said that the static configuration can be accessed by commenting it out, I don't know why.

<!--  Static resource resolution 
     Including: js,css,img... -->
<mvc:resources location="/js/" mapping="/js/**"/> 
<mvc:resources location="/img/" mapping="/img/**"/>

There are others, not 11 listed here. I can't try them all once

Finally settle

Finally, I asked the great god for advice, saying that one jar package of jackson-core was missing, and the configuration contents in application. xml were cut down and pasted into spring-mvc. xml configuration file. And then it was solved ~

Possible reasons why SpringMVC cannot access controller


@RequestMapping(value="/toplayindex",method={RequestMethod.POST,RequestMethod.GET})
public ModelAndView toKpointPlay(HttpServletRequest request,@PathVariable("Id") int Id){
// Code block 
}

Information from the Internet

@PathVariable Get variables from the path @RequestParam Is to get parameters from the request.

For example, the above method requests that the address should be/toplayindex/${id}, and if id is not added to the address, the method will not be requested.


Related articles: