What are the common instructions for JSP (compile instruction/action instruction collation) _jsp programming

Source: Internet
Author: User
Tags character set flush
The JSP contains three compilation instructions and seven action instructions.
Three compilation directives are: page, include, Taglib.
Seven action commands are: Jsp:forward, Jsp:param, Jsp:include, Jsp:plugin, Jsp:usebean, Jsp:setproperty, Jsp:getproperty.
First, compile instructions
1, page instruction
A. Usually at the top of a JSP page, the same page can have multiple page directives. The syntax format is as follows:
Copy Code code as follows:

〈% @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 properties, the general situation is Java, representing the scripting language used for JSP pages.
2 extends attribute, to determine the Java class generated when the JSP program compiles, the parent class that needs to inherit, or the fully qualified class name of the interface that needs to be implemented.
1.import property, which is used to import the package, the following packages are automatically imported by default and do not need to be imported explicitly. The packages that are imported by default are:
Copy Code code as follows:

java.lang.*
javax.servlet.*
javax.servlet.jsp.*
javax.servlet.http.*

2.Session attribute, set whether this JSP page needs Htip session.
The 3.buffer property, specifying the size of the output buffer. JSP internal object for output buffer: Out for caching the output of JSP pages to the client's browser, the default is 8KB, can be set to none, or it can be set to a different value in KB
4.autoFlush property, whether the contents of the output buffer need to be forced when the output buffer is about to overflow. Normal output When set to true, or if set to False, an exception is generated when the buffer overflows.
5.Info property, set the information for the JSP program, or it can be viewed as a description, through the Servlet. The Getservletinfo () method gets the value. If you are in a JSP page, you can call the Getservletinfoo method directly to get the value because the JSP page is essentially a Servlet.
ErrorPage property to specify the error-handling page. If this program produces an exception or error, and the JSP page does not have the corresponding processing code, it will automatically call the JSP page specified by the directive. When using JSP pages, you can not handle exceptions, even checked exceptions. (redirect to the corresponding error-handling page, but the URL is the same as the original URL, does not change) if the page does not have this attribute, then once the code has a problem, it will be prompted in the development environment and IE browser error. It is obvious that this property controls exception handling in a much better form.
6.IsErrorPage property to set whether this JSP page is an error handler. If the page itself is an error-handling page, you do not need to use the ErrorPage property.
7.ContentType property, which is used to set the file format and encoding of the generated Web page, that is, MIME type and page character set type, and the default MIME type is text/html; The default character set is Iso-8859-1.
2, include instructions
With the include directive, you can embed an external file into the current JSP file, parsing the JSP statement (if any) on the page. This is a static include, and does not check for changes to the included JSP page.
Include can contain either static text or dynamic JSP pages. The static compilation instructions include adding the included pages and generating a complete page.
Syntax for include compilation directives:
〈% @include file= "Relativeurlspec"%〉
If the embedded file needs to change frequently, it is recommended to use the <jsp:include> Action directive because it is a dynamic include statement.
The JSP page containing the include directive is deployed, accessed and compiled to generate a Java file, and the corresponding Java file is generated in Tomcat's work\catalina\localhost\project\org\apache\jsp directory. These files are the same as the JSP name, and he contains the compiled code, and even the code of another JSP included with it is joined in accordingly.

Second, the action instruction
1, forward directive: forward instruction is used to forward the page response control to another page. It can be forwarded to a static HTML page, or to a dynamic JSP page, or to a Servlet in a container.
The format of the forward instruction for the JSP is as follows:
For JSP 1. 0, use the following syntax:
Copy Code code as follows:

<jsp:forward page= "{Relativeurl |<%=expression%>}"/>

You can use the following syntax:
Copy Code code as follows:

<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 by the GetParameter method of the HttpServletRequest class.

2, include instruction, it is a dynamic instruction, can be used to import a page. Its import will check for changes to the page being imported each time. The following is the use format for the include directive:
Copy Code code as follows:

<jsp:include page= "{Relativeurl |<%=expression%>}" flush= "true"/>

Or:
Copy Code code as follows:

<jsp:include page= "{Relativeurl |<%=expression%>}" flush= "true" >
<jsp:param name= "paramname" value= "Paramvalue"/>
</jsp:include>

The Flush property is used to specify whether the output cache is transferred to the imported file. If specified as a play. is included in the file being imported, or FALSE, if specified, in the original file. For older versions under JSP 1.1, you can only set to false.
<include> and <jsp:include> are static import and dynamic import respectively. Their difference: Static import is the code that will be imported into the page completely inserted, two pages to generate a whole Servlet; Dynamic import uses dynamic imports in the Servlet to introduce the page.

3, Usebean, setproperty and getproperty instructions
These three directives are javabean-related directives in which Usebean is used to initialize a Java instance on a JSP page, setproperty to modify the properties of the JavaBean instance, GetProperty to obtain the properties of the JavaBean instance.
Syntax format for Usebean:
Copy Code code as follows:

<jsp:usebean id= "" class= "scope=" page | Request |session | Application ">

The ID is the instance name of the JavaBean, and the class attribute determines the implementation class of the JavaBean. The scope property determines the survival scope page, request, session, application
Syntax format for setproperty:
Copy Code code as follows:

<jsp:setproperty name= "property=" "value=" "/>

The Name property determines the need to set the

4, plugin instructions
Plugin instructions are primarily used to download server-side JavaBean or applets to client execution. Because the program executes on the client, the client must install the virtual machine.
The syntax format for plugin is as follows:
Copy Code code as follows:

<jsp:plugin type= "Bean | Applet
Code= "Classfilename"
Codebase= "Classfilediretoryname"
[Name= "InstanceName"]
[archive= "Urltoarchive"]
[align= ' Bottom I top I middle 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, can no. The plugin
</jsp:fallback>]
</jsp:plugin>

The descriptions of these properties are as follows:
Type: Specifies the kind of Java program being executed, whether a bean or an applet
Code: Specifies the name of the file to be executed, which must end with the ". Class" extension
Codebase: Specifies the file directory to be executed.
Name: Give the program a name to identify the program.
Archive: Points to the path of the class that will be used to be preloaded.
Hspace,vspace: Show left and right up and down white.
Jreversion: The JRE version that must be run correctly for the change program.
Nsplugin,ieplugin:netscape Navigator, Internet exploer downloads the address of the JRE required to run.
<jsp:fallback> directive: When the applet is not displayed correctly, replace the displayed message.

5, param instructions
The param instruction is used to set the parameter value, which cannot be used alone because it is meaningless to use alone. It can be combined with the following instructions
Jsp:include
Jsp:forward
Jsp:plugin
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.