我正在使用 Maven 构建 SpringMVC3.2、JSP 和 Tomcat。我的 Web 应用程序结构如下所示。
tomcat
|-- webapps
|-- MyApp
|-- css
|-- js
|-- jquery.js
|-- images
|-- META-INF
|-- WEB-INF
|-- classes
|-- lib
|-- src
|-- web.xml
|-- pages
|-- index.jsp
我在 index.jsp 中设置了 JavaScript 路径,如下所示:
<script src="../js/jquery.js"></script>
但它无法加载 Javascript 文件。我更改了路径并在这里和那里移动了文件,但一切都没有奏效。我错过了什么?请帮我。
提前致谢。
编辑实际上,我通过不同的社区找到了答案。
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
<script src="${contextPath}/js/jquery-1.9.1.js"></script>
</head>
<body>
</body>
</html>
这不是一个漂亮的方式,但它对我来说很好,如果你想要不同的解决方案,请在下面查看我的答案。