1

I'm aware that there are loads of questions on the topic but none of the solutions i found here worked for me. I'm using Spring with Jetty 6 so i don't have a web.xml file. The mapping for the spring dispatcher servlet is set to "/" in jetty's config

dispatcher:

<bean class="org.mortbay.jetty.servlet.ServletHolder">
    <property name="name" value="spring" />
    <property name="servlet">
        <bean class="org.springframework.web.servlet.DispatcherServlet" />
    </property>
    <property name="initParameters">
        <map>
            <entry key="contextConfigLocation" value="classpath:com/project/config/spring-servlet.xml" />
        </map>
    </property>
</bean>

... mapping:

<bean class="org.mortbay.jetty.servlet.ServletMapping">
    <property name="servletName" value="spring"></property>
    <property name="pathSpec" value="/"></property>
</bean>

The spring-servlet.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="..." ...>


<context:component-scan base-package="com.project.web" />
<mvc:annotation-driven />

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

</beans>

And i have a simple controller called HelloController:

@Controller
public class HelloController {

    @RequestMapping(method = RequestMethod.GET, value="/welcome")
    public String sayHello(ModelMap model){
    model.addAttribute("message", "Spring 3 MVC Hello World");
    return "hello";
}

}

Reading the logs it seem to work but i get the following error:

No mapping found for HTTP request with URI [/WEB-INF/pages/hello.jsp] in DispatcherServlet with name 'spring'

which i don't understand. it maps the "/welcome" to /WEB-INF/pages/hello.jsp but it still says page cannot be found, which is just there where it seems to look for it. I added the WEB-INF folder to the classpath but it's still the same. Do you have any idea why's that?

Peter
  • 1,047
  • 2
  • 18
  • 32
  • what is the url that you are using? Is it not `http://your-domain/your-app/welcome` ? – Vinay Nov 06 '12 at 10:01
  • i used http://localhost:25001/welcome – Peter Nov 06 '12 at 10:21
  • check this link: http://stackoverflow.com/questions/3878957/basic-spring-mvc-config-pagenotfound-using-internalresourceviewresolver – user1157934 Nov 06 '12 at 10:46
  • Your link helped, thank you. I changed the dispatcherservlet's mapping to /spring/*. Now when trying http://localhost:25001/spring/welcome i don't get the "no mapping found..." error and the mapping seems correct. However, now the log says: Forwarding to resource [/WEB-INF/pages/hello.html] in InternalResourceView 'hello' and after that i get this: Not Found /WEB-INF/pages/hello.html – Peter Nov 06 '12 at 12:20

3 Answers3

2

Are you sure the package name is correct in this?

<context:component-scan base-package="com.project.web" />
ThinkFloyd
  • 4,981
  • 6
  • 36
  • 56
  • Hm, yes that looks strange, yet I didn't notice it. Unfortunately I can't check it because I won't have access to that codebase at least for a while, but I suppose it would do the trick. – Peter Dec 24 '13 at 13:38
0

The request mapping path in the controller is relative to your http://your-domain/your-app/. If your app name is welcome use url http://localhost:25001/welcome/welcome or change the requestmapping to @RequestMapping(method = RequestMethod.GET, value="/") so you can use url http://localhost:25001/welcome

Vinay
  • 2,667
  • 1
  • 18
  • 21
  • Well I'm not sure i completely understand how this works. Could you explain how this is mapped and what happens when the dispatcherservlet(with mapping "/") recieves the request? That might help. I tried you suggestion though and i got this: when i tried http://localhost:25001/welcome/welcome it was mapped to /welcome/welcome and when i tried changing the requestmapping value from /welcome to / the http://localhost:25001/welcome was mapped to /welcome. Am i missing something? – Peter Nov 06 '12 at 11:01
0

Is your hello.jsp directly under WEB-INF/pages? Can you change the Dispatcher Servlet mapping to this and try

<property name="pathSpec" value="*.html"></property>
Usha
  • 1,458
  • 11
  • 13