This seems trivial, but I am not having any luck trying to discover what I am missing conceptually. This is all within Tomcat 5.5.9 and I am installing the app in webapps/test.
If I use a suffix based servlet mapping in web.xml of,
then I have no problems mapping URLs in my test-servlet.xml context using a SimpleURLHandlerMapping bean to anything ending in .html.Code:<servlet> <servlet-name>test</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>test</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping>
The thing is, I don't want to use suffixed URLs all the time. Obviously there are no restrictions on how I can arrange the mapping and yet, I cannot get things to work and I have been reading a lot of debug logs to try and see what is going wrong. So far, nothing has stood out and the dispatcher is seeing the urlMapping I define.
An example that won't work, is a straightforward variation of that above but now with a path prefix, rather than a ubiquitous suffix.
with a handler bean configured asCode:<servlet> <servlet-name>test</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>test</servlet-name> <url-pattern>/foo/*</url-pattern> </servlet-mapping>
When I try to access the given url say,Code:<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/foo/hello">defaultController</prop> </props> </property> </bean> <bean id="defaultController" class="test.DefaultController"/>
http://localhost:8080/test/foo/hello
[ed. minor edit, typo on the path above]
I can see in the logs that the url is being passed to the dispatcher servlet, but the servlet logs the following.
Could anyone shed some light on what I am misunderstanding? I know url mapping has been discussed many times, but I could not find a discussion that enlightened me.Code:15:04:23,514 DEBUG DispatcherServlet,http-8080-Processor23:811 - Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@b3c24f] in DispatcherServlet with name 'test' 15:04:23,514 DEBUG DispatcherServlet,http-8080-Processor23:811 - Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@b3c24f] in DispatcherServlet with name 'test' 15:04:23,515 DEBUG SimpleUrlHandlerMapping,http-8080-Processor23:130 - Looking up handler for [/hello] 15:04:23,515 DEBUG SimpleUrlHandlerMapping,http-8080-Processor23:130 - Looking up handler for [/hello] 15:04:23,516 DEBUG DispatcherServlet,http-8080-Processor23:750 - No handler found in getLastModified 15:04:23,516 DEBUG DispatcherServlet,http-8080-Processor23:750 - No handler found in getLastModified 15:04:23,517 DEBUG DispatcherServlet,http-8080-Processor23:600 - DispatcherServlet with name 'test' received request for [/test/foo/hello] 15:04:23,517 DEBUG DispatcherServlet,http-8080-Processor23:600 - DispatcherServlet with name 'test' received request for [/test/foo/hello] 15:04:23,517 DEBUG DispatcherServlet,http-8080-Processor23:811 - Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@b3c24f] in DispatcherServlet with name 'test' 15:04:23,517 DEBUG DispatcherServlet,http-8080-Processor23:811 - Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@b3c24f] in DispatcherServlet with name 'test' 15:04:23,518 DEBUG SimpleUrlHandlerMapping,http-8080-Processor23:130 - Looking up handler for [/hello] 15:04:23,518 DEBUG SimpleUrlHandlerMapping,http-8080-Processor23:130 - Looking up handler for [/hello] 15:04:23,519 WARN PageNotFound,http-8080-Processor23:833 - No mapping for [/test/foo/hello] in DispatcherServlet with name 'test' 15:04:23,519 WARN PageNotFound,http-8080-Processor23:833 - No mapping for [/test/foo/hello] in DispatcherServlet with name 'test' 15:04:23,520 DEBUG DispatcherServlet,http-8080-Processor23:409 - Successfully completed request 15:04:23,520 DEBUG DispatcherServlet,http-8080-Processor23:409 - Successfully completed request 15:04:23,520 DEBUG XmlWebApplicationContext,http-8080-Processor23:216 - Publishing event in context [WebApplicationContext for namespace 'test-servlet']: RequestHandledEvent: url=[/test/foo/hello]; time=[3ms]; client=[127.0.0.1]; method=[GET]; servlet=[test]; session=[null]; user=[null]; status=[OK]


Reply With Quote