GET/springMVC/form.jsp没有映射
我正在尝试使用SpringMVC。我的问题是,我的控制器中没有任何请求映射工作,只有我的主页链接“/”工作GET/springMVC/form.jsp没有映射,spring,spring-mvc,Spring,Spring Mvc,我正在尝试使用SpringMVC。我的问题是,我的控制器中没有任何请求映射工作,只有我的主页链接“/”工作 @Controller public class HelloWoldController { @RequestMapping("/") public String showPage() { return "main"; } @RequestMapping("/showForm") public String showForm(
@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>
<?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>
springMVC
调度员
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
/WEB-INF/spring-mvc-demo-servlet.xml
1.
调度员
/
我的spring-mvc-demo-servlet.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>
<?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没有映射请尝试通过为url和方法类型添加值将方法更改为以下
@RequestMapping(value=“/showForm”,method=RequestMethod.GET)
通过为url和方法类型添加值,尝试将方法更改为以下
@RequestMapping(value=“/showForm”,method=RequestMethod.GET)
我不知道它是如何工作的,但我把我的项目改成了maven war项目,而不是动态web app,问题就解决了。如果有人能给出解释的话?我不知道它是如何工作的,但是我把我的项目换成了maven war项目,而不是动态web app,问题就解决了。如果有人能给出解释的话?我遇到了同样的问题,我做了以下几点:
清理您的项目:
在eclipse中,转到项目-->清理
然后右键单击项目并刷新它 面对同样的问题,我做了以下几点: 清理您的项目: 在eclipse中,转到项目-->清理
然后右键单击项目并刷新它 您使用什么url作为主页链接?localhost:8080/springMVC/这是我的主页您使用什么url作为主页链接?localhost:8080/springMVC/这是我的主页仍然不工作,我得到了相同的消息:描述源服务器没有找到目标资源的当前表示,或者不愿意透露存在一个表示--------------------------------------------------------------------------------问题标题中的错误消息与问题描述中的错误消息不同。请确认哪一条是准确的错误消息GET/springMVC/form.jsp无映射,还是GET/springMVC/showForm无映射“GET/springMVC/showForm无映射”消息来自控制台,以及“说明源服务器找不到目标资源的当前表示形式,或者不愿意透露存在该表示形式“从屏幕上看,我创建了一个新项目,而不是动态战争项目,我创建了maven战争项目,它成功了。仍然没有成功,我得到了相同的消息:描述源服务器没有找到目标资源的当前表示,或者不愿意透露存在一个表示--------------------------------------------------------------------------------问题标题中的错误消息与问题描述中的错误消息不同。请确认哪一条是准确的错误消息GET/springMVC/form.jsp无映射,还是GET/springMVC/showForm无映射“GET/springMVC/showForm无映射”消息来自控制台,以及“说明源服务器找不到目标资源的当前表示形式,或者不愿意透露它的存在”来自屏幕我创建了一个新项目,而不是动态war项目,我创建了maven war项目,它成功了。