JSP Tutorial (i)

Source: Internet
Author: User
Tags define expression include variables relative
js| Tutorial

  JSP Overview

JSP (IAVA SERVER pages) is a dynamic Web page production technology developed by Sun Company in the Java language that allows you to separate the dynamic parts of a Web page from the static HTML. You can use tools that are usually handy and write HTML statements in the usual way. The dynamic parts are then embedded with special tags, which often start with "<%" and End With "%>". For example, here is a JSP page:

<body>

<i><%out.println ("Hello World");%></i>

</body>

It will output "Hello World".

Typically, you want to extend the file to ". JSP" and place it under any path that you can place on a normal web page. Although the JSP file looks more like an HTML file than a servlet file, it is actually converted to a servlet file, where static HTML is used only to output information returned by the Servlet service method. If the JSP pages have been converted to a servlet and the servlet is compiled and then loaded (when asked for the first time), when you request this JSP page again, you will not notice a delay. Also note this phenomenon, some Web servers allow you to define aliases for it, as if a URL is pointing to an HTML, but in fact it points to a servlet or JSP pages.

Constructs a JSP page, in addition to the embedded rules of HTML, there are three main types of JSP elements: Scripting elements,directives, and Actions. Using scripting Elements you can define the part that is eventually converted to a servlet, directives allows you to control the overall structure of the servlet, and the actions allow you to specify reusable components that can be reused, as well as control the running of the JSP engine. To simplify scripting elements, you can use some predefined variables, such as request, on a section.

This tutorial is based on the latest version of JSP 1.1, explained. Its syntax is summarized in the following table, and its detailed use is explained in detail in subsequent courses.


JSP elements, syntax, interpretation

JSP Expression
<%= expression%>
Expression is used for calculation and for output.
<jsp:expression> expression </jsp:expression> The predefined variables that can be used are request, response, out, session, Application, config, And PageContext (can also be used in sriptlets).

JSP Scriptlet
<% Code%>
Inserts code for the service.
<jsp:scriptlet> Code </jsp:scriptlet>

JSP Declaration
<!% Code%>
Code that belongs to the servlet section but is not a service method.
<jsp:declaration> Code </jsp:declaration>

JSP page directive
<%@ page att= "Val"%>
Point to the path to the servlet engine.
<jsp:directive.page att= "Val" \> The following are its legitimate properties (the default is bold):

L import= "Package.class"

L contenttype= "Mime-type"

L isthreadsafe= "True|false"

L session= "True|false"

L buffer= "Sizekb|none"

L autoflush= "True|false"

L extends= "Package.class"

L info= "message"

L errorpage= "url"

L iserrorpage= "True|false"

L Language= "Java"

JSP include directive
<%@ include file = "URL"%>
A file on the local system that will be included when the JSP page is translated into a servlet.
<jsp:directive.include file= "url" \> this URL must be relative. "Jsp:include action" is used when the page is requested.

JSP comments
<%--annotation--%>
When the JSP is converted to a servlet, it is ignored.
<--annotation-->

The Jsp:include Action
<jsp:include page= "Relative URL" flush= "true"/>
The page is requested (requested) Si Cho into the file.
If you want the file to be included when the page is converted (translated), use the directive mentioned above instead. Warning: On some servers (Servers), the included files can only be HTML or JSP, usually judged by the suffix name of the file.

The Jsp:usebean Action
<jsp:usebean att=val*/> or <jsp:usebean att=val*>
.....
</jsp:useBean>
Look for or generate a Java Bean.
The possible properties are:

L id= "name"

L scope= "Page|request|session|application"

L class= "Package.class"

L type= "Package.class"

L Beanname= "Package.class"

The Jsp:setproperty Action
<jsp:setproperty att=val*/>
Set the properties of the bean by explicitly specifying or using the parameters obtained by the request.
Valid properties:

L Name= "Beanname"

L property= "propertyname|*"

L param= "ParameterName"

L Value= "Val"

The Jsp:getproperty Action
<jsp:getproperty name= "PropertyName" Value= "Val"/>
Retrieves and outputs the properties of the bean.

The Jsp:forward Action
<jsp:forward page= "Relative URL"/>
Forward requests (Request) another page.

The Jsp:plugin Action
<jsp:plugin attribute= "Value" *>
</jsp:plugin>
Generates an object or embed label for a specific browser to explicitly run the Java plug-in (plugin) used by the applet.



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.