What common jsp instructions are of compile instructions and action instructions collate

  • 2020-06-07 05:09:54
  • OfStack

Jsp contains three compile instructions and seven action instructions.
The three compile instructions are: page, include, taglib.
The seven action instructions are: jsp:forward, jsp:param, jsp:include, jsp:plugin, jsp:useBean, jsp:setProperty, jsp:getProperty.
1. Compile instructions
1. page instruction
a. Usually at the top of an jsp page, you can have more than one page instruction on the same page. The syntax format is as follows:
 
 The < % @page 
[language="Java"] 
[extends="package.class"] 
[import= "package. class I package. *}, ... "] 
[session="true I false"] 
[buffer="none I 8kb I size kb" 1 
[autoFlush="true I false"] 
[isThreadSafe="true I false"] 
[info="text"] 
[errorPage="relativeURL"] 
[contentType="mimeType[ ;charset=characterSet]" I"text/html;charset= "808859-1"] 
[isErrorPage=" true I false"] 
% >  

1)language attribute, 1 The general case is java, which represents the scripting language used by jsp pages.
2)Extends attribute, which determines the Java class generated when the JSP program is compiled, the parent class that needs to be inherited, or the fully qualified class name of the interface that needs to be implemented.
1.import attribute, which is used to import packages. The following packages are automatically imported by default and do not require explicit import. The default imported packages are:
 
java.lang.* 
javax.servlet.* 
javax.servlet.jsp.* 
javax.servlet.http.* 

2.Session attribute. Sets whether HTIP session is required for this JSP page.
3.buffer property, specifying the size of the output buffer. JSP internal object of the output buffer: out is used to cache the output of the JSP page facing the client browser. The default value is 8kb and can be set to none or other values in kb
4.autoFlush property, when the output buffer is about to overflow, whether to force the contents of the output buffer. When set to true, it is the normal output; If set to false, an exception will occur when buffer overflows.
5.Info attribute, which sets the information of the JSP program or can be regarded as its description, can be obtained through the method Servlet.getServletInfo (). If you are on an JSP page, you can call the getServletInfoO method directly to get this value, because an JSP page is essentially Servlet.
The errorPage attribute, which specifies the error handling page. If the program produces an exception or error and the JSP page has no corresponding processing code, the JSP page specified by the directive will be automatically invoked. When using the JSP page, you can not handle exceptions, even if they are checked. (Redirect to the corresponding error handling page, but URL is still the same as URl and does not change.) If this page does not have this property, then once there is a problem with the code, it will prompt an error in the development environment and in the IE browser. This property controls exception handling in a much better way.
6.IsErrorPage attribute, which sets whether the JSP page is an error handler. If the page itself is an error handling page, you do not need to use the errorPage attribute.
7.ContentType attribute, which is used to set the file format and encoding method of generating web pages, namely MIME type and page character set type. The default MIME type is text/html; The default character set is ES87en-8859-1.
2. include instruction
Using the include directive, you can embed an external file into the current JSP file and parse the JSP statements on this page, if any. This is a static include expression and does not check for changes to the JSP page that contains it.
include can contain both static text and dynamic JSP pages. The static compile instruction include is to add the included page to generate a complete page.
include compilation instruction syntax:
< % @include file="relativeURLSpec" % >
If the embedded file needs to be changed frequently, it is recommended to use < jsp:include > Operation instruction because it is a dynamic include statement.
After deployment, jsp page containing include instruction is accessed and compiled to generate java file. In tomcat work\Catalina\ project\org\apache\ apache\jsp directory, the corresponding java file will be generated. These files have the same name as jsp, they contain the compiled code, and even the code of another jsp included by include will be added accordingly.

2. Action instructions
1. forward instruction: forward instruction is used to forward page response control to another page. You can forward to either static HTML pages, dynamic JSP pages, or Servlet in the container.
JSP's forward directive has the following format:
For JSP 1.0, use the following syntax:
 
<jsp:forward page= " {relativeURL |<%=expression%>} "  /> 

The following syntax can be used:
 
<jsp:forward page= " {relativeURL |<%=expression%>} " > 
{<jsp:param ... />} 
</jsp:forward> 

The second syntax is used to add additional request parameters when forwarding. The value of the increased request parameter can be obtained through the getParameter method of the HttpServletRequest class.

2. include instruction, which is a dynamic instruction, can be used to import a page. Its import checks each time the page is imported changes. Here's how the include directive works:
 
<jsp:include page= " {relativeURL |<%=expression%>} "  flush= " true "  /> 

Or:
 
<jsp:include page= " {relativeURL |<%=expression%>} "  flush= " true " > 
<jsp:param name= " paramName "  value= " paramValue " /> 
</jsp:include> 

The flush attribute is used to specify whether the output cache is transferred to the imported file. If specified as a play. Is included in the imported file; If specified as false, it is included in the original file. For older versions up to JSP 1.1, this can only be set to false.
< include > and < jsp:include > Static import and dynamic import, respectively. Their differences: Static import is the complete insertion of the code imported into the page, two pages generate a whole Servlet; Dynamic imports, on the other hand, use dynamic imports in Servlet to bring pages in.

3. useBean, setProperty and getProperty instruction
These three instructions are all related to JavaBean, in which useBean is used to initialize 1 instance of java on the jsp page, setProperty is used to modify the attributes of the JavaBean instance, and getProperty is used to obtain the attributes of the JavaBean instance.
useBean grammar format:
 
<jsp:useBean id= ""  class= ""  scope= " page | request |session | application "  > 

Id is the instance name of JavaBean, and the class attribute determines the implementation class of JavaBean. Scope attribute determines the survival scope [Page, request, session, application]
Syntax format of setProperty:
 
<jsp:setProperty name= ""  property= ""  value= ""  /> 

The Name attribute determination needs to be set

4. plugin instruction
The plugin directive is mainly used to download the server-side JavaBean or Applet to the client for execution. Since the program executes on the client side, the client must install the virtual machine.
The syntax for plugin is as follows:
 
<jsp:plugin type= " bean | applet" 
code="classFileName" 
codebase="classFileDiretoryName" 
[name=" instanceName"] 
[archive="URLtoArchive"] 
[align= "bottom I top I middle I left I right"] 
[heigh="displayPixels"] 
[width="displayPixels"] 
[hspace="leftRightPixels"] 
[vspace="topBottomPiexels"] 
[jreversion=JREVersionNumber|1.2"] 
[nspluginurl="URLToPlugin"] 
[iepluginurl="URLToPlugin"]> 
[<jsp:parames> 
[jsp:param name="parameterName" value="parameterValue" />] 
</jsp:params>] 
[<jsp:fallback>text message for user that can no see the plugin 
</jsp:fallback> ] 
</jsp:plugin> 

These attributes are described as follows:
Type: Specifies the type of java program to be executed, 1 bean or 1 applet
Code: Specifies the filename to be executed. The attribute value must end with the ".class "extension
Codebase: Specifies the directory of files to be executed.
Name: Give the program a name to identify it.
Archive: Points to the path of a class to be loaded in advance.
Hspace,Vspace: Displays the white space left, right, top and bottom.
jreversion: The version of JRE necessary to run the program correctly.
Nsplugin, ieplugin: Netscape Navigator, Internet Exploer Download the address of JRE required to run.
< jsp:fallback > Instruction: Replace the prompt message when the applet cannot be displayed correctly.

5. param instruction
The param directive is used to set parameter values and cannot be used on its own because it does not make sense. It can be used in combination with the following instructions
jsp:include
jsp:forward
jsp:plugin

Related articles: