spring - No mapping for GET /springMVC/form.jsp
问题描述
I'm trying to work with spring mvc. My problem is that no request mapping is working in my controller, only my home page link: "/" is working.
@Controller
public class HelloWoldController {
@RequestMapping("/")
public String showPage() {
return "main";
}
@RequestMapping("/showForm")
public String showForm() {
return "form";
}
}
my web.xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>springMVC</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc-demo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
and my spring-mvc-demo-servlet.xml is:
<?xml version="1.0" encoding="ISO-8859-1"?>
<beans
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans">
<context:component-scan
base-package="com.kaygi22.springmvc" />
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property value="/WEB-INF/view/" name="prefix" />
<property value=".jsp" name="suffix" />
</bean>
Whenever I try to get to the link of showForm, i get this message:
May 09, 2019 4:55:42 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound WARNING: No mapping for GET /springMVC/showForm
解决方案
我遇到了同样的问题,我做了以下事情:清理你的项目:在 Eclipse 中,转到 Project-->clean 并右键单击项目并刷新它。
推荐阅读
- php - imap_open authentication failure on localhost
- python - 如何在 Flask 应用程序中使用条件语句?
- simulation - 是否可以在 scilab Xcos 中创建压力传感器和其他仪器?
- angular - 递归 @SkipSelf 组件的根提供程序
- java - 为什么我的 Java 套接字客户端代码永远循环而不会抛出 IO 异常,即使另一端的服务器已经死了?
- php - Doctrine 分配错误:无法将 Doctrine\ORM\PersistentCollection 分配给属性
- python - Python,如何用大写版本替换匹配的正则表达式模式
- forms - 将网站放在自动化脚本中?
- hyperledger-fabric - 在超级账本结构中升级链码没有错误,但不反映更改
- redis - 使用 MIGRATE 和 COPY 将 Redis 数据库(所有键)从旧 Redis 服务器复制到新 Redis 服务器...