1. include command
Include can insert the JSP code into the JSP code before converting the JSP page to the Servlet. Its main advantage is its powerful functionality. The included code can contain JSP structures that affect the home page in general, such as attributes, method definitions, and document type settings. Its disadvantage is that it is difficult to maintain that the home page must be changed as long as the page to be included is changed, because the home page does not automatically check whether the page to be included is changed.
Syntax: <% @ include file = "sample. jsp" %>
2. include action
The jsp: include action contains the output of the secondary page when the homepage is requested. Although the output of the contained page cannot contain JSP, these pages can be the result of other resources. The server interprets the URL pointing to the contained resource in a normal way. Therefore, the URL can be a Servlet or JSP page. The server runs the contained page in the usual way and places the generated output on the home page. This method is consistent with the include method of the RequestDispatcher class. It does not need to be modified on the home page when the contained page is changed. Its disadvantage is that it contains the output of the secondary page, rather than the actual code of the secondary page, therefore, you cannot use any of the contained pages that may affect the JSP construction of the home page as a whole.
Syntax: <jsp: include page = "sample. jsp "flush =" true "> <jsp: param name =" name "value =" value "/> </jsp: include>
The parameter settings can be left blank. If no parameter is set, the format must be <jsp: include page = "sample. jsp" flush = "true"/>.
3. Main differences between the two
The fundamental difference between jsp: include actions and include commands is the time when they are called. Jsp: The include action is activated during the request, and the include command is activated during page conversion.
The difference between the two determines their differences in use. Pages using the include command are more difficult to maintain than pages using the jsp: include action. As mentioned above, if the JSP page contained in the JSP instruction changes, all the pages on this page must be updated manually. In the relevant specifications of the JSP server, it is not required to detect when the contained files change. In fact, most Server Pages implement this mechanism. This will cause serious maintenance problems. Remember all other pages that contain a page, or re-compile all the pages to make the changes take effect. At this point, jsp: include reflects a very huge advantage, it re-includes resources in each request. Use the jsp: include action whenever possible to implement file inclusion.
Jsp: include operations have obvious advantages over include commands in maintenance, while include commands can still exist. Naturally, they have special advantages in other aspects. This advantage is that the include command has more powerful functions and faster execution speed. The include command allows the included files to contain JSP code that affects the home page, such as the setting of response submission and the definition of attribute methods.