I have develop this example basing uppon the Spring MVC Showcase example.
The result I want to achieve is as follows: a web application that manage 2 kinds of HTTP Request:
FIRST HTTP Request type:: HTTP request towards resources having a structure [/b]/folder[/b]
SECOND HTTP Request type: HTTP request towards resources having a structure [/b]/file.html[/b]
The showcase example manage by default the first type of HTTP Request, so I have add an other DispatcherServlet in my web.xml configuration file to manage the HTTP Request towards *.html
pattern but I am finding some problem to handle the second type of request
So this is my web.xml code:
As you can see in this web.xml fine I have defined 2 DispatcherServlet: the first one that manage the first type of HTTP Request and the second one that manage the second type.
Ok, the DispatcherServlet that manage the HTTP Request towards resources having form: file.html have servlet-name=appServlet2 and it is configured by the servlet2-context.xml configuration file.
This is the code of servlet2-context.xml:
this is a "copy" of the servlet-context.xml file that configure the original DispatcherServlet of the example, the only difference, made by me, is that I import a different file:
controller2.xml
This file simply specify the package in wich are actived the
component scan managed by this
servlet:
So, for this servlet is actived the component scan that search annotation in the following package: org.springframework.samples.mvc2.simple
Ok...In this package I have created the following controller class:
As you can see the sayHello method is annoted by @RequestMapping("/hello") annotation and, in theory, have to manage HTTP Request towards /hello.html file !!!
But don't work well !!!
Adding in my home.jsp view I add these links:
When I click on these links I have the following error message:
HTTP Status 404
....
- description The requested resource is not available.
And this is my stacktrace:
So it is clear that Spring have loaded the appServlet2 DispatcherServlet (the DispatcherServlet that is configured to manage HTTP Request toward filename.html resources) but don't find a mapping for the hello.html resources...
If I change the @RequestMapping("/hello") annotation in @RequestMapping("/hello.html") for my method (inside my HelloController class) the example run well !!!
Using the "/hello.html" pattern inside the @RequestMapping annotation, Spring find the mapping with my sayHello() method and all run well !!!
Infact this is the relative stack trace (the HTTP reuqest is is properly managed by appServlet2 DispatcherServlet and the sayHello() method is called)
I think that this behavior is very very strange because the appServlet2 is configured to handle automatically HTTP request toward resources shaped as: "filename.html" because I have mapped this kind of resources in my web.xml file by the tag:
But if I don't specify that the .html in the @RequestMapping annotation don't work...
The strange thing is that I have created an other simplify Spring project (outside the Spring MVC Showcase Project) and in this one I have not this mapping problem...
Why? Someone can help me to understand this thing? I am going crazy
Thank you very much for your attenction
Andrea