0

I am trying to make a very simple example to map all requests to a particular JSP. My web.xml is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">

    <display-name>Spring MVC Static Resources</display-name>

    <servlet>
        <servlet-name>StaticServlet</servlet-name>
        <jsp-file>/index.jsp</jsp-file>
    </servlet>

    <servlet-mapping>
        <servlet-name>StaticServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

And here it is my index.jsp:

<!DOCTYPE html>
<html lang="en">
<head>
    <link type="text/css" rel="stylesheet" href="resources/css/main.css" />
    <script type="text/javascript" src="resources/js/jquery.1.10.2.min.js"></script>
    <script type="text/javascript" src="resources/js/main.js"></script>
</head>
<body>
<h1>1. Test CSS JSP</h1>

<h2>2. Test JS JSP</h2>
<div id="msg"></div>

</body>
</html>

The mapping is working fine, the problem is when the JSP tries to load the CSS and JS files in the <head/>. Then I see next messages in the Chrome console:

enter image description here

If I remove that mapping and let the web.xml as simple as this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">

    <display-name>Spring MVC Static Resources</display-name>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

</web-app>

Then the resources are loaded properly.

I tried to create an index.html file and place inside the code from my JSP, and then just put inside my JSP next line:

<%@ include file="index.html" %>

But the result is the same.

Just to sum up, the mapping is working fine but I cannot find a solution to load resources specified in the <head/> element.

Thank you for your help.

rocotocloc
  • 418
  • 6
  • 19
  • you capture is fine but you should unfold the error line :) – davidxxx Jul 23 '16 at 09:39
  • I was mixing several concepts and this resources problem has been solved with BalusC link reference. I'll try to post a most specific question if I can't solve my real issue. Thanks a lot. – rocotocloc Jul 25 '16 at 10:16

0 Answers0