The code execution loading sequence in the jsp page is described

  • 2020-11-03 22:33:30
  • OfStack

java is code that runs on the server side, jsp runs on the server's servlet, and javascript and html are code that runs on the browser side. So the order of load execution is java > jsp > js.

2. Loading sequence of js in jsp

The js code on the page is part 1 of the html code, so the page loads from top to bottom. So the order in which js loads is in the page < script > The order in which tags appear. < script > The order in which the external js file is executed within the tag or imported is the order in which the statement appears, and the process performed by js is also part 1 of the page load.

2.1 The global variables and functions defined in the js script can be called in the following script. The call to the variable must have been previously declared, otherwise the variable returns undefined. In the same script, a function definition can appear after a function call; If a function is defined and called in two script segments, the function call will report an undefined function error before the function definition.

2.2 Asynchronous loading of ajax appears in js

The asynchronous loading of ajax may cause statements to be executed in a different order than the order in which they were executed. Here's an example of a problem I encountered while working on a task:

At the initial load of the page, a request is sent to jsp to obtain the data needed for the page. In the ajax success function, the operation on data takes too long, causing confirm and loadTree outside the ajax function to execute before the statement following the data operation. Finally, the value of using data in loadTree is null, and the global variable openTab_Id is null.

2.3 Control js execution sequence

You can use setTimeout(function(),time); Enable function to load lazily.


Related articles: