SpringMVC出现no mapping found for http request的解决办法

来源:互联网 发布:mac如何下载视频 编辑:程序博客网 时间:2024/05/23 00:06

SpringMVC出现no mapping found for http request的解决办法

错误一:
检查web.xml中的<servlet-mapping></servlet-mapping><url-pattern></url-pattern>

<servlet-mapping>        <servlet-name>springmvc</servlet-name>        <url-pattern>/*</url-pattern>    </servlet-mapping> 改为:     <servlet-mapping>        <servlet-name>springmvc</servlet-name>        <url-pattern>/</url-pattern>    </servlet-mapping>

错误二:
检查springmvc的配置文件(这里我的文件名为springmvc.xml):

这里有两点需要注意:

  1. 必须开启注解<mvc:annotation-driven />
  2. <context:component-scan base-package="com.xrda.controller"></context:component-scan>中的base-package需要是包级别的。 下边是我的项目中的包
    项目包

错误三:
还有一个确定的因素在这里也贴出来吧,如果以上两种方法都不行的话可以试试:

在springmvc配置文件中配置<mvc:default-servlet-handler/>
跟错误二是同一个文件

错误四:

这个错误是比较好发现的,就是映射的地址写错了,比如:

@Controller@RequestMapping(value = "/test")public class FileUploadController {    @RequestMapping(value = "/upload.htm" , method = RequestMethod.POST)    public String upload(MultipartFile uploadFile,HttpSession session) throws IllegalStateException, IOException{        String fileName = uploadFile.getOriginalFilename();        String filePath = session.getServletContext().getRealPath("upload");        File file = new File(filePath, fileName);        uploadFile.transferTo(file);        System.out.println(filePath);        return "message";    }}   我们访问的时候的地址应该是http://localhost:8080/项目名/test/upload.htm

菜鸟一枚,大神勿喷。

阅读全文
0 0