I'm developing a web application in java using Spring MVC 3.2.2. I'm having problems loading jsp page from within the jar file.
The Sring MVC web application that the following structure:
|-META-INF
|-WEB-INF
|-spring
| |- app-config.xml
|-classes
|-lib
| |-external.jar
| |-WEB-INF
| | |-views
| | |-external.jsp
| |-classes
| |-controller-for-external.class
|-views
|-... jsp
Config in app-config.xml
<context:annotation-config />
<context:component-scan base-package="com" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/WEB-INF/views/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<mvc:resources mapping="/views/**" location="classpath:/WEB-INF/views/" />
<mvc:annotation-driven />
Controller for external.jsp
@Controller
public class ExternalController {
protected final Log logger = LogFactory.getLog(getClass());
@RequestMapping(value="/external.htm")
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Map<String, Object> myModel = new HashMap<String, Object>();
myModel.put("msg", "External page loaded");
return new ModelAndView("external", "model", myModel);
}
}
web.xml file
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>Springapp</display-name>
<servlet>
<servlet-name>springapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/app-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/app-config.xml</param-value>
</context-param>
<servlet-mapping>
<servlet-name>springapp</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
</web-app>
When a try to show external.jsp page, spring don't want search it and show error HTTP 404 - /springapp/WEB-INF/views/external.jsp