1. Java is the code that runs on the server side, and the JSP runs in the server's servlet, while JavaScript and HTML are code that runs on the browser side. So the load execution order is JAVA>JSP>JS.
2. JS in the JSP in the loading sequence
The JS code on the page is part of the HTML code, so when the page loads it is loaded from the top down. So the order of JS loading is the order of <script> label appearing in the page. <script> tags inside or the introduction of the external JS file is the order of execution of its statements appear in the order in which the process of JS execution is also part of the page load.
2.1 Global variables and functions defined in the JS script can be invoked in a later script . The call to the variable must be previously declared, otherwise the value returned by the variable is undefined. In the same script, the function definition can appear after the function's call, and if the function's definition and invocation are in two script segments, the function call will report the function undefined error before the function definition.
Asynchronous loading of Ajax in 2.2 JS
Because of the asynchronous loading of Ajax, the execution order of the statements is not performed in the order in which they appear. Here's an example of the problem I encountered while doing my task:
When the page is initially loaded, you need to send a request to the JSP to get the data needed for the page, in the Ajax success function, the operation of the data takes too long, it will cause the confirm and loadtree outside the AJAX function to execute the statement after the data operation. The final use of data in the Loadtree is worth the time, when the global variable opentab_id is empty.
2.3 Control JS Execution order
You can use settimeout (function (), time) to delay the load of a function.