I had made a basic application on spring mvc framework.
when i write the following url pattern on web.xml:
<servlet-mapping>
<servlet-name>springxml</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
and runs the application (using ../SpringMVCXML/welcome.jsp) , it displays HTTP Status 404 error.
When I changes the url pattern other than .jsp, application is running fine.
Why Application is not running on .jsp url pattern?
I had used following java class act as controller.
@Controller
@RequestMapping(value="/welcome",method=RequestMethod.GET)
public class ControllerHello {
@RequestMapping(method=RequestMethod.GET)
public String printHello(ModelMap map) {
map.addAttribute("message", "Hello Spring MVC Framework");
return "hello";
}
}
Also, my springxml-servlet.xml had following code:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
Assuming you have also springxml servlet is also serving other views than *.jsp (you might have other servlet-mappings in your web.xml), the situation is as follows:
You registered a controller for the path /welcome, not for /welcome.jsp. Therefore, /welcome.jsp is not mapped to a Spring mvc controller. The /welcome HelloController will give you the String output hello.
/welcome.jsp will give an error 404, since it is in WEB-INF and there is no Spring MVC controller for that url.
The org.springframework.web.servlet.view.InternalResourceViewResolver is meant to put your jsp files inside /WEB-INF. Look at http://www.mkyong.com/spring-mvc/spring-mvc-internalresourceviewresolver-example/ for a simple explanation for what the InternalResourceResolver does. Basically, it enables Spring MVC to use a jsp, that is not in your public resources, as a view. It is not a mechanism to register these jsps as valid urls.
The urls are determined in the requestmappings.