私はSpring MVCを初めて使用しています。小さなhello worldアプリケーションを作成しようとしましたが、期待通りに動作していません。 私は常にエラー org.springframework.web.servlet.DispatcherServlet noHandlerFound 警告を取得しています:マッピングは[/FitnessTracker/greeting.html]名前を持つのDispatcherServletに「fitTrackerServlet」org.springframework.web.servlet.DispatcherServlet noHandlerFound:Spring MVC
私はこれを知っているURIとHTTPリクエストが見つかりませんエラーは非常に一般的であり、Googleで利用可能なリンクがたくさんありますが、いずれも私のために働いていませんでした。どんな助けもありがとう。ここ
は、コードスニペット
HelloController.java
@Controller
public class HelloController {
@RequestMapping(value = "/greeting")
public String sayHello(Model model) {
model.addAttribute("greeting","Hello World!!!!");
return "hello";
}}
Hello.jspのある
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
Insert title here
</title>
</head>
<body>
<h1>
${greeting}
</h1>
</body>
</html>
fitTrackerServlet-servlet.xml
<?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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<mvc:annotation-driven/>
<context:annotation-config/>
<context:component-scan base-package="com.firstspringmvc.controller"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp"/>
</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"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>fitTrackerServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>fitTrackerServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
URL /greeting
は末尾に.html
を持っていないので、サーブレットはのDispatcherServletを使用するつもりはありません
てみ名前「contextConfigLocation」と値を使用してサーブレットdefintionにXMLのパスをINIT-PARAMとしてあなたのXMLを追加します。 コントローラー定義がロードされていない可能性があります。 – helospark
'/ url-pattern>'このようなURLパターンを与えて、一度試してください。jspページはjspアプリケーションではHTMLではありません。 –
Hema
@helosparkこれも試しましたが動作しませんでした –