java我的jsp文件找不到我的javascript文件
我的jsp文件找不到我的javascript文件。在这里您可以看到我的jsp文件:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="ressources/js/addMatrix.js"></script>
</head>
<body>
<div ng-app="App" ng-controller="MainCtrl">
<p>Add a new element : </p>
<table>
<tr>
<td data-ng-repeat="data in texts">
<button>{{data.text}}</button>
</td>
<td data-ng-repeat="field in fields">
<form ng-submit="submit(text)">
<input type="text" ng-model="text" name="text"
placeholder="New Category" />
</form>
</td>
<td>
<button ng-click="addNewChoice()">+</button>
</td>
</tr>
</table>
</div>
</body>
</html>
我的javascript文件位于/WebContent/resources/js文件夹中,jsp文件位于/WebContent文件夹中
My servlet仅在get方法中包含此调用:
this.getServletContext().getRequestDispatcher("/index.jsp").forward(req, resp);
还有我的网络。xml文件如下所示:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Home</servlet-name>
<servlet-class>com.pi.servlets.Index</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Home</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
等待你的帮助。谢谢
# 1 楼答案
你可以在chrome中打开它,点击f12按钮,然后在“源”选项卡下,你可以看到它是否已连接
# 2 楼答案
我不是JavaEE dev,所以这可能不是最好的解决方案,但我认为这可能是一个好的开始
<script src="ressources/js/addMatrix.js"></script>
在客户端执行。因为它不是绝对路径但相对的,它会根据当前位置(可供浏览器使用的URL)尝试查找
ressources
目录。所以如果你的URL是它会努力找到它
而不是
resources
简单的解决方法是使您的路径相对于服务器的根目录(所以以
/
开头),并包含项目名称:或者,为了使其更具动态性,您可以使用EL以
/project
的形式读取项目名称,这样您的代码可以如下所示: