'Spring no mapping found for HTTP request with URI[require.js] in DispatcherServlet
Ok the full error is WARNING: No mapping found for HTTP request with URI [/sequenziatore/$%7BpageContext.request.contextPath%7D/resources/js/libs/require.js] in DispatcherServlet with name 'spring'
When i start the web app on a tomcat7 server, it open on the right page index.jsp, but it doesn't load the script require.js...I looked around for the other post and i find to add ${pageContext.request.contextPath} when requesting the require.js and also adding to the spring-servlet.xml
but it gives me this error, i also moved all the css and js in a folder called resources but nothing...Without the ${pageContext.request.contextPath} it gives me the same error..
The web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
And the spring-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.presenter"/>
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />
</beans>
And the index.jsp:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link rel="stylesheet" href="resources/css/screen.css">
<link rel="stylesheet" href="resources/css/jquery.mobile-1.4.2.min.css">
<script data-main="js/main" src="${pageContext.request.contextPath}/resources/js/libs/require.js"></script>
</head>
<body>
<div data-role="page" id="home"></div>
<div data-role="page" id="page2"></div>
</body>
</html>
Solution 1:[1]
Remove the ${pageContext.request.contextPath} and data-main="js/main" will become resources/js/main
Solution 2:[2]
Add a Maven dependency support for JSP in pom.xml file and remove web.xml file.
<!-- Add support for JSP -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
</dependency>
Or,
simply remove this ${pageContext.request.contextPath}
Now, the issue will get resolved.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | SweSirius |
Solution 2 |