Failed to introduce js and css files in jsp files, jscss
I recently set up a project that fails to introduce js and css files in jsp. The cause of failure is the absolute path and relative path:
File structure:
Jsp code:
<%@ page contentType="text/html;charset=UTF-8" language="java" %><%@ taglib uri="https://java.sun.com/jsp/jstl/core" prefix="c"%><% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; System.out.println(basePath);%>
<Script type = "text/javascript" src = "$ {basePath} assets/js/jquery/jquery-3.2.1.js"> </script> The absolute path used in the process fails to be introduced, and modification to the relative path also fails.
Solution:
In browser developer mode, 404 error is reported when a static file is introduced, so the resource cannot be accessed,
You need to configure the static resource directory in the springmvc. xml file:
Then OK.