【发布时间】:2019-10-23 21:02:46
【问题描述】:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>sample</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sample</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
我在其中添加了表单和操作“输出”的索引文件
<html>
<body> <form action="output">
<input type="text" name="t1"></br> <input type="text" name="t2"></br>
<input type="submit">
</form>
</body>
</html>
servlet 配置如下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.guni.Controllers"></context:component-scan>
</beans>
sampleController.java
package com.guni;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class sampleController {
@RequestMapping(value="/output", method = RequestMethod.GET)
public String karna()
{
return "sampleOutput.jsp";
}
}
我正在尝试使用提交按钮执行表单 GET。提交按钮没有任何反应。该网页给了我404错误。任何人都有任何想法。我正在使用 eclipse 2019 和 tomcat9。我正在尝试使用 spring 4.0 在 maven 中创建一个 Web 应用程序
当我运行项目时,它给了我以下错误 org.springframework.web.servlet.DispatcherServlet noHandlerFound GET /demoMVC/output 没有映射
【问题讨论】:
标签: java spring maven web model-view-controller