-2

Hi everyone I'm developping covoiturage app and I have a problem with the navigation between pages. when i click on a link to go to anther page i have the problem "no mapping found for http request with uri in dispatcherservlet with name mvc-dispatcher" thank you

<annotation-driven />

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />

<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/" />
    <beans:property name="suffix" value=".jsp" />
</beans:bean>

<context:component-scan base-package="com.covoiturage.app" />


    <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>

org.springframework.web.context.ContextLoaderListener

user0321
  • 113
  • 1
  • 10
  • 1
    Please edit your question and put code fragments there. Include stack traces, if any. – Evil Toad Aug 18 '15 at 08:51
  • when i click on a link i have always WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/app/login] in DispatcherServlet with name 'appServlet' – user0321 Aug 18 '15 at 08:57

1 Answers1

0

The exception you get says that the URL you are trying to navigate to is forwarded to the DispatcherServlet, but isn't mappend on any web controllers. To be more specific, if you map your DispatcherServlet on the root context, like this

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

and then you have, say, an HTML page with a link like this

<a href="/my-url">click me</a>

To make the navigation happen you need a class annotated with @Controller that has a method to which the URL is mapped (note the @RequestMapping annotation):

@Controller
public class TestPageController
{       
    @RequestMapping(path = "/my-url")
    public String getTestPage()
    {
        return "renderViewName";
    }
}
Evil Toad
  • 3,053
  • 2
  • 19
  • 28
  • I need to create a classe for each page ? – user0321 Aug 18 '15 at 09:09
  • No, as long as the class is annotated with `@Controller` and the method with `@RequestMapping`, you can create as many controllers as you want (i.e. only one if you wish so). Generally I see one controller for each html or jsp page, but, again, this is for you to decide. – Evil Toad Aug 18 '15 at 09:14
  • I have done what you say and I resolve the problem for the login page,but when I try to click SignUp page I have the problem "org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/app/SignUp] in DispatcherServlet with name 'appServlet" – user0321 Aug 18 '15 at 09:21
  • Well I guess that it much depends on what happens when you "click SignUp" page. Is that a submit button inside a form? Is that a link? What is its URL? Plus, remember that all the controllers must be inside the package specified in the component-scan element of the config (but maybe you've just checked it). **EDIT** You need `@RequestMapping(path = "/app/SignUp")` – Evil Toad Aug 18 '15 at 09:29
  • i ty to access from a link like that – user0321 Aug 18 '15 at 09:32
  • i have one controller inside – user0321 Aug 18 '15 at 09:35
  • Please mark the answer as accepted if it solves your problem. Thank you. – Evil Toad Aug 18 '15 at 10:16