Effective solution of JSP loading JS file does not work

Time:2020-10-18

Directory structure: JSP importing jQuery files always does not work because:

Copy codeThe code is as follows:
<script type=”text/javascript” src=”js/jquery-1.4.2.min.js”></script>

It cannot access the files in the / WEB-INF / directory, so you need to put the loaded JS file into the webapp directory.
Effective solution of JSP loading JS file does not work 
test.html:

Copy codeThe code is as follows:
<%@ page language=”java” %>
<%@ page contentType=”text/html; charset=UTF-8″ %>
<%@ page import=”java.util.*” %>
<%@ page isELIgnored=”false” %>

<%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core” %>
<%@ taglib prefix=”fmt” uri=”http://java.sun.com/jsp/jstl/fmt” %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”;
%>

<html>
<head>
<base href=”<%=basePath%>” />
<link rel=stylesheet type=”text/css” href=”css/style.css”/>
<script type=”text/javascript” src=”js/jquery-1.5.1.min.js”></script>

<script type=”text/javascript”>
$(document).ready(function() {
alert(“hello, jquery”);
});
</script>

< title > login
</head>

<body>
<p><%=basePath%></p>
</body>
</html>