jeudi 14 avril 2016

The requested resource is not available simple Spring MVC app

I am trying to create a simple Spring MVC app and I don't know why I get error 404 The requested resource is not available.

This is the xml file :

    <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://ift.tt/19L2NlC"
         xmlns:xsi="http://ift.tt/ra1lAU"
         xsi:schemaLocation="http://ift.tt/19L2NlC http://ift.tt/1drxgYl"
         version="3.1">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

The dispatcher serlvet:

<?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"
       xsi:schemaLocation="http://ift.tt/GArMu6 http://ift.tt/1jdM0fG
       http://ift.tt/GArMu7 http://ift.tt/1bGeTcI
       http://ift.tt/1bHqwjR http://ift.tt/JWpJWM">


    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsps/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <context:component-scan base-package="controllers" />
    <mvc:annotation-driven />
</beans>

my controller handles just a simple model:

@org.springframework.stereotype.Controller
public class Controller {

    @RequestMapping("/")
    public String getData(Model model) {
        model.addAttribute("message", "Hello World!");
        return "index";
    }
}

And the JSP file! I just want to print the message from the controller.

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
  <h1>${message}</h1>
  </body>
</html>




Aucun commentaire:

Enregistrer un commentaire