【发布时间】:2019-09-27 13:54:10
【问题描述】:
我正在尝试使用 spring mvc。我的问题是我的控制器中没有请求映射在工作,只有我的主页链接:“/”在工作。
@Controller
public class HelloWoldController {
@RequestMapping("/")
public String showPage() {
return "main";
}
@RequestMapping("/showForm")
public String showForm() {
return "form";
}
}
我的 web.xml 文件是:
<?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>
而我的 spring-mvc-demo-servlet.xml 是:
<?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>
每当我尝试访问 showForm 的链接时,我都会收到以下消息:
2019 年 5 月 9 日下午 4:55:42 org.springframework.web.servlet.DispatcherServlet noHandlerFound 警告:GET /springMVC/showForm 没有映射
【问题讨论】:
-
你用什么网址做主页链接?
-
localhost:8080/springMVC/ 这是我的主页
标签: spring spring-mvc