What's wrong with my Url Mappings?
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 dis开发者_StackOverflow中文版playing 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>
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?
精彩评论