页面刷新时JavaScript未加载,伴随External Exception问题求助
Hey there, let's break down what's going wrong here and fix it step by step!
First off, I spotted a critical typo in your code that's almost certainly triggering the External Exception:
In the return statement, you wrote
docMsgErroinstead ofdocMsgError(missing the 'r' at the end).
This typo will cause a runtime error (like an undefined variable exception) when the code executes, which throws the External Exception. When the server hits this error, it likely sends a broken or incomplete HTTP response instead of the proper error page—this is why your JavaScript fails to load entirely on refresh.
Fixed Code Example
if(sendTOList.isEmpty()) { ShowableDoc docMsgError = new ShowableDoc(); docMsgError.addField("msg", "sample_text"); // Corrected the variable name typo here return new SessionHtml( getErrorFile(), docMsgError, session ); }
Additional Troubleshooting Steps
If fixing the typo doesn't resolve the issue entirely, here are more things to check:
- Check Server Logs: Look for the full stack trace of the External Exception. It will pinpoint exactly where the error occurs—maybe
getErrorFile()returns an invalid path, or theSessionHtmlconstructor has an unhandled exception when processing theShowableDocobject. - Validate the Error Page: Make sure the file returned by
getErrorFile()exists and has correct JavaScript references. If the error page uses relative paths for JS files, a refresh might break those paths depending on the current URL structure. - Test the Happy Path: Verify that when
sendTOListis NOT empty, the page loads correctly and JavaScript works as expected. This will help isolate whether the issue is specific to the error branch of your code.
内容的提问来源于stack exchange,提问作者jotape

