Generally, JSP runs in the following way: when the server is started and the web browser sends a page request, the web server first determines whether the request is a JSP page request. If this page is only a common html/XML page request CodeTo the web browser. Compile the servlet code, convert it into a bytecode (. Class) file, call the Java Virtual Machine to execute the bytecode file, and then pass the execution result to the Web browser. If the JSP page is not requested for the first time and has not been modified, the JSP Engine directly calls the Java Virtual Machine to execute the compiled bytecode. class file, and then transfer the result to the Web browser. Below is a JSP running:
From this, we can see the relationship between JSP and Servlet. the JSP Engine is responsible for translating JSP pages into servlet. Therefore, JSP at the underlying layer is completely servlet (refers to the original concept servlet, instead of httpservlet ). As mentioned above, JSP programming corresponds to javax. servlet. JSP, more specifically, this package is used by the JSP Engine and needs to be used for translation, we do not need to use this package when writing JSP pages.
Why is it necessary to implement a JSP at the high-level level with Servlet? This problem is related to the complexity of servlet compilation. If you use servlet to control the page appearance, it will be a headache, using JSP, we handed over complicated printing tasks to the JSP Engine,ProgramMembers can focus on logical control.