CarbonMan
CarbonMan

Reputation: 4490

Simple Servlet mapping

I am trying to implement Spring onto a small app. I am getting the following:

WARNING: No mapping found for HTTP request with URI [/audiClave/] in DispatcherServlet with name 'appServlet'

Here is my web.xml file:

<?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/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    id="WebApp_ID" 
    version="3.0">
    <display-name>audiClave</display-name>
<!-- Processes application requests -->
<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-                            class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>      

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

And here is the servlet-context.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: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.0.xsd
    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">

<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

<!-- Scans within the base package of the application for @Components to configure as beans -->
<!-- @Controller, @Service, @Configuration, etc. -->
<context:component-scan base-package="com.audiClave.Service" />

<!-- Enables the Spring MVC @Controller programming model -->
<mvc:annotation-driven />

</beans>

The controller is:

package com.audiClave.Service;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController {

@RequestMapping(value = "/")
public String home() {
    System.out.println("HomeController: Passing through...");
    return "WEB-INF/views/home.jsp";
}
}   

http://localhost:8080/audiClave/ returns:

HTTP Status 404
The requested resource () is not available.

I am running under eclipse using tomcat 7.0.12 and spring 3.0.5. The content appears to be correctly deployed to E:\development\java.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\audiClave

When I changed the mapping to /* it was able to find the controller, but then the home.jsp doesn't work because the wild card matches it as well

RESOLVED when I took the /* out of the mapping again. Thanks

Upvotes: 0

Views: 2873

Answers (2)

user1931091
user1931091

Reputation: 1

The problem should be this:
In file [filename]-servlet.xml please enter the following line:
< mvc:resources location="/index.html" mapping="/index.html" />

Upvotes: 0

Bozho
Bozho

Reputation: 597362

Do just return "home" (instead of the whole path to the jsp). The View handler should be configured to look for the views in that folder, with that extension.

Upvotes: 1

Related Questions