Я пытаюсь начать с Spring MVC & Tomcat, однако я, похоже, не могу создать одиночный обработчик для рендеринга минималистической страницы , были созданыSpring MVC: Нет сопоставления для HTTP-запроса с URI [/hello.jsp]
следующие файлы:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="springapp" 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
http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>springapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springapp-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springapp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<display-name>Spring MVC Framework Test</display-name>
</web-app>
springapp-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" xmlns:mvc="http://www.springframework.org/schema/cache"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:cache="http://www.springframework.org/schema/c"
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 http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<!--<mvc:annotation-driven />-->
<context:component-scan base-package="springapp.web.*"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean name="/hello.jsp" class="springapp.web.HelloController"/>
</beans>
hello.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>JSP Title</title>
</head>
<body>
${message}
</body>
</html>
HelloController.java структура
package springapp.web;
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
public class HelloController {
@RequestMapping(value="/hello", method=RequestMethod.GET)
public String printHello(ModelMap model) {
model.addAttribute("message", "Hello Spring MVC Framework!");
return "hello";
}
}
Папка:
Мои попытки найти обработчик:
16-Aug-2016 16:31:18.867 WARNING [http-nio-8080-exec-8] org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/springapp/hello.jsp] in DispatcherServlet with name 'springapp'
16-Aug-2016 16:31:22.991 WARNING [http-nio-8080-exec-9] org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/springapp/web/hello.jsp] in DispatcherServlet with name 'springapp'
16-Aug-2016 16:31:23.023 WARNING [http-nio-8080-exec-10] org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/springapp/web/hello.jsp] in DispatcherServlet with name 'springapp'
Может кто-то мольбы скажите мне, что я делаю неправильно?
Что вы пытаетесь добиться от этой линии? . Не нужно это делать. а также это значение = "/ hello.jsp"? –
Вы правы! Удаление этой линии не повлияло на текущую ситуацию. – rolandvarga
@RequestMapping (value = "/ hello.jsp" ... неверно. Должно быть @RequestMapping (value = "/ hello" ... если вы пробовали это, пожалуйста, обновите свой вопрос –