使用 Glassfish 在 javaEE 中加载 js 页面的奇怪情况

Weird situation loading js pages in javaEE with Glassfish

事情是这样的:当我尝试加载一个不存在的页面时(例如 http://localhost:8080/XXXX/kgdfkjcd), the 404 error page should appear. But instead, the page loaded is http://localhost:8080/XXXX/,我不明白为什么!

这也是我的 css/js 文件的问题: 我试图在 webContent 文件夹下放置一个 test.js 文件,并使用代码行加载它:

<script type="text/javascript" src="test.js"></script>

这是一个简单的 javascript 文件,我只是把 :

console.log("test")

然后,我重新加载,检查控制台并查看:

test.js:4 Uncaught SyntaxError: Unexpected token <

没错,显然是找不到文件 test.js,而是加载了 http://localhost:8080/XXXX/ 页面。 (当然,当一个 js 文件以...

开头时
<DOCTYPE....

...有一个 javascript 问题。

我在很多论坛上搜索了很多,但找不到有类似问题的人。

有人有解决方案吗?

这是我的web.xml:

<?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" xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
  <display-name>XXXX</display-name>
  <jsp-config>
    <jsp-property-group>
      <url-pattern>*.jsp</url-pattern>
      <include-prelude>/WEB-INF/header.jsp</include-prelude>
      <include-coda>/WEB-INF/footer.jsp</include-coda>
    </jsp-property-group>
  </jsp-config>
  <listener>
    <listener-class>
        com.orvif.config.InitilisationApp
    </listener-class>
  </listener>
</web-app>

好吧,我没有找到解决方案,但我知道问题出在哪里...是 glassfish。我尝试完全使用 tomcat 并且它有效...如果有人找到其他解决方案,请不要犹豫。