Я создал файл войны и сохранил его в каталоге webapps в tomcat и запустил tomcat, но когда я нахожусь http://localhost:8181/HelloWeb/hello Я получаю ошибку 404. Я новичок в Spring mvc, любая помощь будет оценена по достоинству. Ниже приведены мои файлы (делают пример, приведенный в http://www.tutorialspoint.com/spring/spring_mvc_hello_world_example.htm.Получение ошибки 404 при обращении от Spring MVC
HelloController.java
package dummyPackageOne;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/hello")
public class HelloController {
@RequestMapping(method=RequestMethod.GET)
public String printHello(ModelMap modelMap){
modelMap.addAttribute("message", "this is the message");
return "hello";
}
}
это мой hello.jsp
<%@ page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h2>${message}</h2>
</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="dummyPackageOne" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>springTest</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>/</url-pattern>
</servlet-mapping>
</web-app>
Как называется ваш .war-файл? Это HelloWeb.war, ROOT.war или что-то еще? – Jason
Также вы можете видеть, что ваш .war-файл распаковывается Tomcat (также в папке webapp)? – Jason
springTest.war и распакован именем springTest. и в папке WEB-INF у меня есть HelloWeb-servlet.xml, web.xml, classes/HelloController.java, jsp/hello.jsp, lib/* jars (все файлы jar). – user3718420