dimanche 28 mai 2017

Spring Web Application - The requested resource is not available

I would like to ask you for an advice what could be wrong with my easy tutorial example of spring web applications.

I am trying to reach website on this URL:

http://localhost:8084/SpringTutorial/hello

As a response to this URL I get HTTP 404 - Resource not available - from apache tomcat server.

Here is the code:

web.xml

<?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.1" xmlns="http://ift.tt/19L2NlC" xmlns:xsi="http://ift.tt/ra1lAU" xsi:schemaLocation="http://ift.tt/19L2NlC http://ift.tt/1drxgYl">
        <display-name>SpringTutorial</display-name>
        <servlet>
            <servlet-name>spring-dispatcher</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>/WEB-INF/spring-dispatcher-servlet.xml</param-value>
            </init-param>

            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>spring-dispatcher</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
    </web-app>

spring-dispatcher-servlet.xml

<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?xml version="1.0" encoding="UTF-8"?> -->
<beans xmlns = "http://ift.tt/GArMu6"
   xmlns:context = "http://ift.tt/GArMu7"
   xmlns:xsi = "http://ift.tt/ra1lAU"
   xsi:schemaLocation = "http://ift.tt/GArMu6     
   http://ift.tt/QEDs1e
   http://ift.tt/GArMu7 
   http://ift.tt/QEDs1k">

    <!-- Scanning for anotation base classes (controllers) -->
    <context:component-scan base-package="com.controllers" /> 
    <!-- Using anotation based classes (controllers) -->
    <mvc:annotation-driven/>

    <bean id="viewResolver"
          class="org.springframeúwork.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/jsp/"
          p:suffix=".jsp" />

</beans>

HelloController.java

package com.controllers;

import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.portlet.ModelAndView;

@Controller
public class HelloController {

    @RequestMapping(value="/hello", method = RequestMethod.POST)
    public ModelAndView sayHello(){
        ModelAndView hello = new ModelAndView("HelloPage");
        hello.addObject("message", "Welcome at first Spring web application");
        return hello;
    }        
}

HelloPage.jsp
Displaying message attribute.

Here is the image of project folder hierarchy




Aucun commentaire:

Enregistrer un commentaire