You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JavaEE(Glassfish)环境下页面跳转异常及JS/CSS加载问题

Troubleshooting Your 404 Redirect & JS Loading Issues

Hey there, let's walk through fixing these two pesky issues one by one. I've run into similar stuff before, so here are the most likely fixes to check:

1. Fixing the Misbehaving 404 Page (Redirecting to Root Instead)

This usually boils down to server configuration or routing rules overriding the default 404 behavior. Here's what to check:

  • Verify your web.xml error page setup: Make sure you've explicitly mapped 404 errors to your custom page. Add this snippet if it's missing:
    <error-page>
        <error-code>404</error-code>
        <location>/404.html</location> <!-- Replace with your actual 404 page path -->
    </error-page>
    
  • Check for rogue filters or redirect rules: If you're using a framework like Spring MVC, double-check interceptors or view controllers—sometimes a misconfigured rule will catch all unknown requests and redirect them to the root. For example, a wildcard route that's set to redirect instead of throwing a 404.
  • Test the 404 page directly: Visit http://localhost:8080/XXXX/404.html (or your actual 404 page URL) to confirm the page itself loads correctly. If it doesn't, fix that first before worrying about the redirect.
  • Check server-wide config: For Tomcat users, peek into conf/web.xml in your Tomcat installation—sometimes the default error page settings get modified, causing unexpected redirects.

2. Fixing the test.js Loading Exception

Static resource issues are almost always path-related or blocked by framework rules. Let's troubleshoot:

  • Validate the path: The relative path src="test.js" will look for the file at the same level as your current page. If your page is at http://localhost:8080/XXXX/some/subpage, it'll try to load http://localhost:8080/XXXX/some/test.js instead of the root. Try using an absolute path to rule this out:
    <script type="text/javascript" src="/XXXX/test.js"></script>
    
  • Check browser dev tools: Open your browser's Network tab and look for the test.js request. What's the status code? If it's 404, the file isn't where you think it is. If it's 500, there's a server-side issue serving static files.
  • Unblock static resources (framework-specific): If you're using Spring MVC, you need to add <mvc:default-servlet-handler/> to your context config—otherwise, the framework will treat static JS files as controller requests and return 404.
  • Double-check the JS file: Even simple code can have typos (like missing semicolons or mismatched brackets). Load the JS file directly in your browser (http://localhost:8080/XXXX/test.js) to make sure it renders correctly, no server errors.

内容的提问来源于stack exchange,提问作者etienne31

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:06:36