Reputation: 745
I have been told in this post that it is possible to have .jsp extension in URL structure using Spring. I have been trying to achieve it with the following code:
HelloController.java
@Controller
@RequestMapping("/welcome")
public class HelloController {
@RequestMapping(value="/item.jsp", method = RequestMethod.GET)
public String helloDotJSP(ModelMap model) {
System.out.println("/item.jsp RequestMapping");
model.addAttribute("message", "Spring 3 MVC Hello World");
return "item";
}
}
And when I try to access the page localhost:8080/app/welcome/item.jsp I get the error that The requested resource is not available. But when I try to just modify the extension from /item.jsp to for example /item.other it starts working. How can I add support for .jsp extension?
Thank you for your help.
Upvotes: 2
Views: 1349
Reputation: 3198
You are getting the "requested resource is not available" because I your servlet mapping in the web.xml
is not mapping item.jsp
to the Spring DispatcherServlet
.
Regardless, if your requirement is just to support old URLs, there are more effective ways of doing it.
Most lo-fi is to create jsps that with the same name and structure as the old urls, and in each of these jsps add scriptlets like
<%
response.setStatus(301);
response.setHeader( "Location", "/new-url.htm" );
response.setHeader( "Connection", "close" );
%>
I don't usually recommend scriptlets but in cases like these, its the simplest solution.
You can also add 301 redirect rules if you have a fronting webserver like apache.
Hope this helps.
Upvotes: 1