在具有名称[duplicate]的DispatcherServlet中找不到具有URI的HTTP请求的映射(No mapping found for HTTP request with URI… in

编程入门 行业动态 更新时间:2024-10-27 10:26:01
在具有名称[duplicate]的DispatcherServlet中找不到具有URI的HTTP请求的映射(No mapping found for HTTP request with URI… in DispatcherServlet with name [duplicate])

这个问题已经在这里有一个答案:

为什么Spring MVC回应404,并报告“在DispatcherServlet中没有使用URI [...]发送HTTP请求的映射”? 3个答案

我几乎检查了几乎每一篇关于stackoverflow的相关文章,但我只是无法解决我的问题。

这里是代码:web.xml:

<display-name>Spring3MVC</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-servlet.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet> <servlet-name>spring</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>*.html</url-pattern> <url-pattern>/</url-pattern> <url-pattern>*.htm</url-pattern> </servlet-mapping> </web-app>

为spring-servlet.xml:

<context:component-scan base-package="com.mycompany.elso" /> <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/> <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean>

myController的:

public class myController { @RequestMapping("/hello") public ModelAndView helloWorld() { String message = "Hello World, Spring 3.0!"; return new ModelAndView("hello", "message", message); } }

网页/ index.jsp:

<html> <head> <title>Spring 3.0 MVC Series</title> </head> <body> <a href="hello.html">Say Hello</a> </body> </html>

网页/ WEB-INF / jsp / hello.jsp:

<html> <head> <title>Spring 3.0 MVC Series: Hello World - ViralPatel.net</title> </head> <body> ${message} </body> </html>

所以当我启动应用程序index.jsp正确加载,但是当我点击href导航到hello.jsp我有一个404错误,服务器日志说:

No mapping found for HTTP request with URI [/Elso/hello.html] in DispatcherServlet with name 'spring'

我查了几十篇这样的文章,但是我找不到错误,任何人都有什么想法呢?

This question already has an answer here:

Why does Spring MVC respond with a 404 and report “No mapping found for HTTP request with URI […] in DispatcherServlet”? 6 answers

I checked out nearly every relevant article on stackoverflow already, but I just cant fix my problem.

Here is the code: web.xml:

<display-name>Spring3MVC</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-servlet.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet> <servlet-name>spring</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>*.html</url-pattern> <url-pattern>/</url-pattern> <url-pattern>*.htm</url-pattern> </servlet-mapping> </web-app>

spring-servlet.xml:

<context:component-scan base-package="com.mycompany.elso" /> <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/> <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean>

myController:

public class myController { @RequestMapping("/hello") public ModelAndView helloWorld() { String message = "Hello World, Spring 3.0!"; return new ModelAndView("hello", "message", message); } }

Web Pages/index.jsp:

<html> <head> <title>Spring 3.0 MVC Series</title> </head> <body> <a href="hello.html">Say Hello</a> </body> </html>

Web Pages/WEB-INF/jsp/hello.jsp:

<html> <head> <title>Spring 3.0 MVC Series: Hello World - ViralPatel.net</title> </head> <body> ${message} </body> </html>

So when i launch the appication the index.jsp is loaded correctly but when i click on the href to navigate to hello.jsp i got a 404 error and the server log says:

No mapping found for HTTP request with URI [/Elso/hello.html] in DispatcherServlet with name 'spring'

I've checked out dozens of articles like that, but I just can't find the mistake, anybody has any idea what could it be?

最满意答案

您可以尝试在myController Class之上添加一个@Controller注释,并尝试以下url /<webappname>/my/hello.html 。 这是因为org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping在myController类中为每个RequestMapping添加/ my

You could try and add an @Controller annotation on top of your myController Class and try the following url /<webappname>/my/hello.html. This is because org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping prepends /my to each RequestMapping in the myController class.

更多推荐

hello,jsp,web,DispatcherServlet,电脑培训,计算机培训,IT培训"/> <meta name=&qu

本文发布于:2023-08-05 05:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1427964.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中找   名称   DispatcherServlet   duplicate   request

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!