Я новичок в Spring. Я пытаюсь создать проект Spring MVC SpringWorld. В коде нет ошибки, но по какой-то причине, когда я запускаю его на localhost, я получаю " запрос не найден ". Я перепроверял программу, но не смог решить проблему. Может ли кто-нибудь сказать мне, что случилось?Ошибка «request not found» в Spring MVC
ControllerClass.java (внутри папки Src)
@Controller
@RequestMapping("/hello")
public class ControllerClass {
@RequestMapping(method = RequestMethod.GET)
public String printHello(ModelMap model){
model.addAttribute("message", "Hello Spring MVC Framework");
return "hello";
}
}
hello.jsp (внутри папки Jsp в веб-инф)
<%@ page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<title>Spring MVC example</title>
</head>
<body>
<h1>${message}</h1>
</body>
</html>
HelloWeb-servlet.xml (внутри веб-инф)
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.springmvcexample.xyz" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
web.xml (внутри Lib папки веб-РСМД)
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>HelloWeb</servlet-name>
<servlet-class> org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HelloWeb</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
</web-app>
Вы propertly Забегая страницы Java Server, например Tomcat? На какой URL вы обращаетесь? Для меня все выглядит отлично, поэтому постарайтесь найти ошибку из коробки. – kazbeel
Является ли 'hello.jsp' расположенным в /WEB-INF/jsp/hello.jsp? Хм, есть много глупых причин, почему это не работает. – kazbeel
Является ли ваш 'HelloWeb-servlet.xml' ссылкой в вашем 'web.xml'? – ccheneson