<?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>
the index file where I added a form and action "output"
<html>
<body> <form action="output">
<input type="text" name="t1"></br> <input type="text" name="t2"></br>
<input type="submit">
</form>
</body>
</html>
The servlet is configured as below
<?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";
}
}
I am trying to execute a form GET with submit button. the Submit button does not respond any thing. The web page gives me 404 error. Any body has any idea.I am using eclipse 2019 and tomcat9. i am trying to create a web application in maven using spring 4.0
When i run the project it gives me the bellow error org.springframework.web.servlet.DispatcherServlet noHandlerFound No mapping for GET /demoMVC/output
Your controller method is registered to accept GET requests on /output
, while you're performing a GET request on /demoMVC/output
. Either modify your @RequestMapping
value to /demoMVC/output
, or change the URL you're calling in your browser.
Furthermore, in many cases an InternalResourceViewResolver
is configured to return the name of the JSP file without the .jsp
suffix. Assuming you've created a file named sampleOutput.jsp
, adjust your karna()
method to return "sampleOutput"
instead of "sampleOutput.jsp"
. If this does not work, would you be able to you post your InternalResourceViewResolver
configuration?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.