I'm building a very simple Spring app. I am using Spring tool suite 3.6.4, Tomcat 8.0. But it is crashing when access /greeting mapping. It returns HTTP Status 404 - /FitnessTracker/greeting Requested Resource is not available And the app is not invoking the controller because Console is not displaying nothing with System.out.println. Please help, What I am doing wrong?
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://ift.tt/nSRXKP"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/nSRXKP http://ift.tt/LU8AHS">
<servlet>
<servlet-name>fitnessTrackerServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/servlet-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>fitnessTrackerServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<display-name>Archetype Created Web Application</display-name>
</web-app>
servlet-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:context="http://ift.tt/GArMu7"
xmlns:mvc="http://ift.tt/1bHqwjR"
xmlns:p="http://ift.tt/1jdM0fE"
xsi:schemaLocation="http://ift.tt/1bHqwjR http://ift.tt/JWpJWM
http://ift.tt/GArMu6 http://ift.tt/1jdM0fG
http://ift.tt/GArMu7 http://ift.tt/1bGeTcI">
<mvc:annotation-driven/>
<context:component-scan base-package="com.thewizardofoz.controllers"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
</beans>
HelloController.java
package com.thewizardofoz.controllers;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HelloController {
private static Logger logger = Logger.getLogger(HelloController.class);
@RequestMapping(value="/greeting")
public String sayHello(Model model) {
System.out.println("I passed by here");
model.addAttribute("greeting", "Welcome to our world!");
return "hello";
}
public HelloController() {
System.out.println("Hello Controller loaded");
}
}
hello.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://ift.tt/kTyqzh">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>${greeting}</h1>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire