views:

84

answers:

1

I am trying to map a couple urls to their respective controllers as follows:

/index.html => HomeController
/login/index.html = LoginController

My mapping bean in my servlet xml looks like this:

<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
        <map>
            <entry key="/index.html">
                <ref bean="homeController" />
            </entry>
            <entry key="/login/index.html">
                <ref bean="loginController" />
            </entry>
        </map>
    </property>
</bean>

I have properly defined the ref beans for homeController and loginController.

I can load the home page properly, but when I try to navigate to /login, instead of displaying the jsp pointed to by loginController, I get tomcat requested resource unavailable error. Is there something wrong with my syntax here? Thanks

Heres a portion of my web.xml:

<servlet>
    <servlet-name>myServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>myServlet</servlet-name>
    <url-pattern>/index.html</url-pattern>
</servlet-mapping>

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>
+1  A: 

Your URL mapping is /login/index.html, and you're navigating to /login.

Your URL mappings have to match the URL. Change the mapping to /login

edit: OK, the url-pattern in your web.xml is only catching the index page, so it never sends requests for /login to Spring. You either need to widen the pattern to be <url-pattern>/*</url-pattern> (which will send every request to Spring), or add multiple patterns to cover each URL you want Spring to handle.

Also your welcome-file-list is a bit excessive. Do you actually need any of those?

skaffman
This didn't do it. Do I maybe need to change my servlet-mapping in web.xml?
es11
Possibly. What's in your `web.xml`?
skaffman
I updated the question with my web.xml
es11
Hmm..when I change the patter to /*, I get the following error on the consol: No mapping found for HTTP request with URI [/my-app/] in DispatcherServlet with name 'myServlet'...and yes I agree my welcome-file-list is excessive
es11
weird..I got it working by adding the patter '/login' to my servlet-mapping. For some reason it only works if I omit the '.html' for the login page in both web.xml and the servlet mapping. This is confusing because it catches the homepage as 'index.html'...
es11