I have an issue with intercepting request to static resources by controller.
Here is web.xml (part related with the problem):
<servlet>
<servlet-name>testing</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>testing</servlet-name>
<url-pattern>/testing/*</url-pattern>
</servlet-mapping>
Here is testing-servlet.xml:
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/WEB-INF/resources/" />
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
Here is controller class source code:
@Controller
@RequestMapping(value = "/testing")
public class TestingController {
@RequestMapping(method = RequestMethod.GET)
public String doSomething() {
return "doView";
}
@RequestMapping(value = "/getSomething", method = RequestMethod.GET)
public String getSomething(@RequestParam String id) {
return "getView";
}
}
And the last snipet of doView.jsp and getView.jsp files with declaration of static file with JavaScript:
<script src="testing/resources/js/jquery.js"></script>
There is one thing I don't understand - why do I get doView.jsp by entering only http://localhost:8080/app/testing
but in order to get getView.jsp I need to enter http://localhost:8080/app/testing/testing/getSomething
("testing" typed twice).
And now the main reason of this topic - when I remove request mapping annotation from class definition (@RequestMapping(value = "/testing")
and leave those on methods then I'm not able to get jquery.js file at all. When I type http://localhost:8080/app/testing/resources/js/jquery.js
I get doView.jsp. There isn't any issue reported by developer tool in browser (missing jquery.js file or something) - this request is just intercepted by Spring's dispatcher servlet. The only advantage in this configuration is that I don't have to type "testing" twice in order to open getView.jsp. ;)
Does anyone know solution how to make mvc:resources
tag working in such situation? And no I can't set URL mapping of whole testing servlet to "/". ;)