分享
 
 
 

JSP

王朝html/css/js·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

. Syntax Summary

JSP Element

Syntax

Interpretation

Notes

JSP Expression

<%= expression %>

Expression is evaluated and placed in output.

XML equivalent is

<jsp:expression>

expression

</jsp:expression>. Predefined variables are request, response, out, session, application, config, and pageContext (available in scriptlets also).

JSP Scriptlet

<% code %>

Code is inserted in service method.

XML equivalent is

<jsp:scriptlet>

code

</jsp:scriptlet>.

JSP Declaration

<%! code %>

Code is inserted in body of servlet class, outside of service method.

XML equivalent is

<jsp:declaration>

code

</jsp:declaration>.

JSP page Directive

<%@ page att="val" %>

Directions to the servlet engine about general setup.

XML equivalent is

<jsp:directive.page att="val"\>. Legal attributes, with default values in bold, are:

import="package.class"

contentType="MIME-Type"

isThreadSafe="true|false"

session="true|false"

buffer="sizekb|none"

autoflush="true|false"

extends="package.class"

info="message"

errorPage="url"

isErrorPage="true|false"

language="java"

JSP include Directive

<%@ include file="url" %>

A file on the local system to be included when the JSP page is translated into a servlet.

XML equivalent is

<jsp:directive.include

file="url"\>.

The URL must be a relative one. Use the jsp:include action to include a file at request time instead of translation time.

JSP Comment

<%-- comment --%>

Comment; ignored when JSP page is translated into servlet.

If you want a comment in the resultant HTML, use regular HTML comment syntax of <-- comment -->.

The jsp:include Action

<jsp:include

page="relative URL"

flush="true"/>

Includes a file at the time the page is requested.

If you want to include the file at the time the page is translated, use the page directive with the include attribute instead. Warning: on some servers, the included file must be an HTML file or JSP file, as determined by the server (usually based on the file extension).

The jsp:useBean Action

<jsp:useBean att=val*/> or

<jsp:useBean att=val*>

...

</jsp:useBean>

Find or build a Java Bean.

Possible attributes are:

id="name"

scope="page|request|session|application"

class="package.class"

type="package.class"

beanName="package.class"

The jsp:setProperty Action

<jsp:setProperty att=val*/>

Set bean properties, either explicitly or by designating that value comes from a request parameter.

Legal attributes are

name="beanName"

property="propertyName|*"

param="parameterName"

value="val"

The jsp:getProperty Action

<jsp:getProperty

name="propertyName"

value="val"/>

Retrieve and output bean properties.

The jsp:forward Action

<jsp:forward

page="relative URL"/>

Forwards request to another page.

The jsp:plugin Action

<jsp:plugin

attribute="value"*>

...

</jsp:plugin>

Generates OBJECT or EMBED tags, as appropriate to the browser type, asking that an applet be run using the Java Plugin.

3. Template Text: Static HTMLIn many cases, a large percent of your JSP page just consists of static HTML, known as template text. In all respects except one, this HTML looks just like normal HTML, follows all the same syntax rules, and is simply "passed through" to the client by the servlet created to handle the page. Not only does the HTML look normal, it can be created by whatever tools you already are using for building Web pages. For example, I used Allaire's HomeSite for most of the JSP pages in this tutorial.

The one minor exception to the "template text is passed straight through" rule is that, if you want to have "<%" in the output, you need to put "<\%" in the template text.

4. JSP Scripting ElementsJSP scripting elements let you insert Java code into the servlet that will be generated from the current JSP page. There are three forms:

Expressions of the form <%= expression %> that are evaluated and inserted into the output,

Scriptlets of the form <% code %> that are inserted into the servlet's service method, and

Declarations of the form <%! code %> that are inserted into the body of the servlet class, outside of any existing methods. Each of these is described in more detail below.

4.1 JSP ExpressionsA JSP expression is used to insert Java values directly into the output. It has the following form: <%= Java Expression %>

The Java expression is evaluated, converted to a string, and inserted in the page. This evaluation is performed at run-time (when the page is requested), and thus has full access to information about the request. For example, the following shows the date/time that the page was requested: Current time: <%= new java.util.Date() %>

To simplify these expressions, there are a number of predefined variables that you can use. These implicit objects are discussed in more detail later, but for the purpose of expressions, the most important ones are:

request, the HttpServletRequest;

response, the HttpServletResponse;

session, the HttpSession associated with the request (if any); and

out, the PrintWriter (a buffered version of type JspWriter) used to send output to the client. Here's an example: Your hostname: <%= request.getRemoteHost() %>

Finally, note that XML authors can use an alternative syntax for JSP expressions: <jsp:expression>

Java Expression

</jsp:expression>

Remember that XML elements, unlike HTML ones, are case sensitive. So be sure to use lowercase.

4.2 JSP ScriptletsIf you want to do something more complex than insert a simple expression, JSP scriptlets let you insert arbitrary code into the servlet method that will be built to generate the page. Scriptlets have the following form: <% Java Code %>

Scriptlets have access to the same automatically defined variables as expressions. So, for example, if you want output to appear in the resultant page, you would use the out variable. <%

String queryData = request.getQueryString();

out.println("Attached GET data: " + queryData);

%>

Note that code inside a scriptlet gets inserted exactly as written, and any static HTML (template text) before or after a scriptlet gets converted to print statements. This means that scriptlets need not contain complete Java statements, and blocks left open can affect the static HTML outside of the scriptlets. For example, the following JSP fragment, containing mixed template text and scriptlets <% if (Math.random() < 0.5) { %>

Have a <B>nice</B> day!

<% } else { %>

Have a <B>lousy</B> day!

<% } %>

will get converted to something like: if (Math.random() < 0.5) {

out.println("Have a <B>nice</B> day!");

} else {

out.println("Have a <B>lousy</B> day!");

}

If you want to use the characters "%>" inside a scriptlet, enter "%\>" instead. Finally, note that the XML equivalent of <% Code %> is <jsp:scriptlet>

Code

</jsp:scriptlet>

4.3 JSP DeclarationsA JSP declaration lets you define methods or fields that get inserted into the main body of the servlet class (outside of the service method processing the request). It has the following form: <%! Java Code %>

Since declarations do not generate any output, they are normally used in conjunction with JSP expressions or scriptlets. For example, here is a JSP fragment that prints out the number of times the current page has been requested since the server booted (or the servlet class was changed and reloaded): <%! private int accessCount = 0; %>

Accesses to page since server reboot:

<%= ++accessCount %>

As with scriptlets, if you want to use the characters "%>", enter "%\>" instead. Finally, note that the XML equivalent of <%! Code %> is <jsp:declaration>

Code

</jsp:declaration>

5. JSP DirectivesA JSP directive affects the overall structure of the servlet class. It usually has the following form: <%@ directive attribute="value" %>

However, you can also combine multiple attribute settings for a single directive, as follows: <%@ directive attribute1="value1"

attribute2="value2"

...

attributeN="valueN" %>

There are two main types of directive: page, which lets you do things like import classes, customize the servlet superclass, and the like; and include, which lets you insert a file into the servlet class at the time the JSP file is translated into a servlet. The specification also mentions the taglib directive, which is not supported in JSP version 1.0, but is intended to let JSP authors define their own tags. It is expected that this will be the main new contribution of JSP 1.1.

5.1 The JSP page DirectiveThe page directive lets you define one or more of the following case-sensitive attributes:

import="package.class" or import="package.class1,...,package.classN". This lets you specify what packages should be imported. For example:

<%@ page import="java.util.*" %>

The import attribute is the only one that is allowed to appear multiple times.

contentType="MIME-Type" or

contentType="MIME-Type; charset=Character-Set"

This specifies the MIME type of the output. The default is text/html. For example, the directive

<%@ page contentType="text/plain" %>

has the same effect as the scriptlet

<% response.setContentType("text/plain"); %>

isThreadSafe="true|false". A value of true (the default) indicates normal servlet processing, where multiple requests can be processed simultaneously with a single servlet instance, under the assumption that the author synchronized access to instance variables. A value of false indicates that the servlet should implement SingleThreadModel, with requests either delivered serially or with simultaneous requests being given separate servlet instances.

session="true|false". A value of true (the default) indicates that the predefined variable session (of type HttpSession) should be bound to the existing session if one exists, otherwise a new session should be created and bound to it. A value of false indicates that no sessions will be used, and attempts to access the variable session will result in errors at the time the JSP page is translated into a servlet.

buffer="sizekb|none". This specifies the buffer size for the JspWriter out. The default is server-specific, but must be at least 8kb.

autoflush="true|false". A value of true, the default, indicates that the buffer should be flushed when it is full. A value of false, rarely used, indicates that an exception should be thrown when the buffer overflows. A value of false is illegal when also using buffer="none".

extends="package.class". This indicates the superclass of servlet that will be generated. Use this with extreme caution, since the server may be using a custom superclass already.

info="message". This defines a string that can be retrieved via the getServletInfo method.

errorPage="url". This specifies a JSP page that should process any Throwables thrown but not caught in the current page.

isErrorPage="true|false". This indicates whether or not the current page can act as the error page for another JSP page. The default is false.

language="java". At some point, this is intended to specify the underlying language being used. For now, don't bother with this since java is both the default and the only legal choice. The XML syntax for defining directives is <jsp:directive.directiveType attribute=value />

For example, the XML equivalent of <%@ page import="java.util.*" %>

is <jsp:directive.page import="java.util.*" />

5.2 The JSP include DirectiveThis directive lets you include files at the time the JSP page is translated into a servlet. The directive looks like this: <%@ include file="relative url" %>

The URL specified is normally interpreted relative to the JSP page that refers to it, but, as with relative URLs in general, you can tell the system to interpret the URL relative to the home directory of the Web server by starting the URL with a forward slash. The contents of the included file are parsed as regular JSP text, and thus can include static HTML, scripting elements, directives, and actions.

For example, many sites include a small navigation bar on each page. Due to problems with HTML frames, this is usually implemented by way of a small table across the top of the page or down the left-hand side, with the HTML repeated for each page in the site. The include directive is a natural way of doing this, saving the developers from the maintenance nightmare of actually copying the HTML into each separate file. Here's some representative code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>

<HEAD>

<TITLE>Servlet Tutorial: JavaServer Pages (JSP) 1.0</TITLE>

<META NAME="author" CONTENT="webmaster@somesite.com">

<META NAME="keywords" CONTENT="...">

<META NAME="description" CONTENT="...">

<LINK REL=STYLESHEET

HREF="Site-Styles.css"

TYPE="text/css">

</HEAD>

<BODY>

<%@ include file="/navbar.html" %>

<!-- Part specific to this page ... -->

</BODY>

</HTML>

Note that since the include directive inserts the files at the time the page is translated, if the navigation bar changes, you need to re-translate all the JSP pages that refer to it. This is a good compromise in a situation like this, since the navigation bar probably changes infrequently, and you want the inclusion process to be as efficient as possible. If, however, the included files changed more often, you could use the jsp:include action instead. This includes the file at the time the JSP page is requested, and is discussed in the tutorial section on JSP actions.

6. Example Using Scripting Elements and DirectivesHere is a simple example showing the use of JSP expressions, scriptlets, declarations, and directives. You can also download the source or try it on-line. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>

<HEAD>

<TITLE>Using JavaServer Pages</TITLE>

<META NAME="author" CONTENT="Marty Hall -- hall@apl.jhu.edu">

<META NAME="keywords"

CONTENT="JSP,JavaServer Pages,servlets">

<META NAME="description"

CONTENT="A quick example of the four main JSP tags.">

<LINK REL=STYLESHEET

HREF="My-Style-Sheet.css"

TYPE="text/css">

</HEAD>

<BODY BGCOLOR="#FDF5E6" TEXT="#000000" LINK="#0000EE"

VLINK="#551A8B" ALINK="#FF0000">

<CENTER>

<TABLE BORDER=5 BGCOLOR="#EF8429">

<TR><TH CLASS="TITLE">

Using JavaServer Pages</TABLE>

</CENTER>

<P>

Some dynamic content created using various JSP mechanisms:

<UL>

<LI><B>Expression.</B><BR>

Your hostname: <%= request.getRemoteHost() %>.

<LI><B>Scriptlet.</B><BR>

<% out.println("Attached GET data: " +

request.getQueryString()); %>

<LI><B>Declaration (plus expression).</B><BR>

<%! private int accessCount = 0; %>

Accesses to page since server reboot: <%= ++accessCount %>

<LI><B>Directive (plus expression).</B><BR>

<%@ page import = "java.util.*" %>

Current date: <%= new Date() %>

</UL>

</BODY>

</HTML>

Here's a typical result:

7. Predefined VariablesTo simplify code in JSP expressions and scriptlets, you are supplied with eight automatically defined variables, sometimes called implicit objects. The available variables are request, response, out, session, application, config, pageContext, and page. Details for each are given below.

7.1 requestThis is the HttpServletRequest associated with the request, and lets you look at the request parameters (via getParameter), the request type (GET, POST, HEAD, etc.), and the incoming HTTP headers (cookies, Referer, etc.). Strictly speaking, request is allowed to be a subclass of ServletRequest other than HttpServletRequest, if the protocol in the request is something other than HTTP. This is almost never done in practice.

7.2 responseThis is the HttpServletResponse associated with the response to the client. Note that, since the output stream (see out below) is buffered, it is legal to set HTTP status codes and response headers, even though this is not permitted in regular servlets once any output has been sent to the client.

7.3 outThis is the PrintWriter used to send output to the client. However, in order to make the response object (see the previous section) useful, this is a buffered version of PrintWriter called JspWriter. Note that you can adjust the buffer size, or even turn buffering off, through use of the buffer attribute of the page directive. This was discussed in Section 5. Also note that out is used almost exclusively in scriptlets, since JSP expressions automatically get placed in the output stream, and thus rarely need to refer to out explicitly.

7.4 sessionThis is the HttpSession object associated with the request. Recall that sessions are created automatically, so this variable is bound even if there was no incoming session reference. The one exception is if you use the session attribute of the page directive (see Section 5) to turn sessions off, in which case attempts to reference the session variable cause errors at the time the JSP page is translated into a servlet.

7.5 applicationThis is the ServletContext as obtained via getServletConfig().getContext().

7.6 configThis is the ServletConfig object for this page.

7.7 pageContextJSP introduced a new class called PageContext to encapsulate use of server-specific features like higher performance JspWriters. The idea is that, if you access them through this class rather than directly, your code will still run on "regular" servlet/JSP engines.

7.8 pageThis is simply a synonym for this, and is not very useful in Java. It was created as a placeholder for the time when the scripting language could be something other than Java.

8. ActionsJSP actions use constructs in XML syntax to control the behavior of the servlet engine. You can dynamically insert a file, reuse JavaBeans components, forward the user to another page, or generate HTML for the Java plugin. Available actions include:

jsp:include - Include a file at the time the page is requested. See Section 8.1.

jsp:useBean - Find or instantiate a JavaBean. See Section 8.2 for an overview, and Section 8.3 for details.

jsp:setProperty - Set the property of a JavaBean. See Section 8.4.

jsp:getProperty - Insert the property of a JavaBean into the output. See Section 8.5.

jsp:forward - Forward the requester to a new page. See Section 8.6.

jsp:plugin - Generate browser-specific code that makes an OBJECT or EMBED tag for the Java plugin. See Section 8.7. These actions are described in more detail below. Remember that, as with XML in general, the element and attribute names are case sensitive.

8.1 The jsp:include ActionThis action lets you insert files into the page being generated. The syntax looks like this: <jsp:include page="relative URL" flush="true" />

Unlike the include directive, which inserts the file at the time the JSP page is translated into a servlet, this action inserts the file at the time the page is requested. This pays a small penalty in efficiency, and precludes the included page from containing general JSP code (it cannot set HTTP headers, for example), but it gains significantly in flexibility. For example, here is a JSP page that inserts four different snippets into a "What's New?" Web page. Each time the headlines change, authors only need to update the four files, but can leave the main JSP page unchanged.

WhatsNew.jspYou can also download the source or try it on-line. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>

<HEAD>

<TITLE>What's New</TITLE>

<LINK REL=STYLESHEET

HREF="My-Style-Sheet.css"

TYPE="text/css">

</HEAD>

<BODY BGCOLOR="#FDF5E6" TEXT="#000000" LINK="#0000EE"

VLINK="#551A8B" ALINK="#FF0000">

<CENTER>

<TABLE BORDER=5 BGCOLOR="#EF8429">

<TR><TH CLASS="TITLE">

What's New at JspNews.com</TABLE>

</CENTER>

<P>

Here is a summary of our four most recent news stories:

<OL>

<LI><jsp:include page="news/Item1.html" flush="true"/>

<LI><jsp:include page="news/Item2.html" flush="true"/>

<LI><jsp:include page="news/Item3.html" flush="true"/>

<LI><jsp:include page="news/Item4.html" flush="true"/>

</OL>

</BODY>

</HTML>

Here's a typical result:

8.2 The jsp:useBean ActionThis action lets you load in a JavaBean to be used in the JSP page. This is a a very useful capability because it lets you exploit the reusability of Java classes without sacrificing the convenience that JSP adds over servlets alone. The simplest syntax for specifying that a bean should be used is: <jsp:useBean id="name" class="package.class" />

This usually means "instantiate an object of the class specified by class, and bind it to a variable with the name specified by id." However, as we'll see shortly, you can specify a scope attribute that makes the bean associated with more than just the current page. In that case, it is useful to obtain references to existing beans, and the jsp:useBean action specifies that a new object is instantiated only if there is no existing one with the same id and scope. Now, once you have a bean, you can modify its properties via jsp:setProperty, or by using a scriptlet and calling a method explicitly on the object with the variable name specified earlier via the id attribute. Recall that with beans, when you say "this bean has a property of typeX called foo", you really mean "this class has a method called getFoo that returns something of type X, and another method called setFoo that takes an X as an argument." The jsp:setProperty action is discussed in more detail in the next section, but for now note that you can either supply an explicit value, give a param attribute to say that the value is derived from the named request parameter, or just list the property to indicate that the value should be derived from the request parameter with the same name as the property. You read existing properties in a JSP expression or scriptlet by calling the appropriate getXxx method, or more commonly, by using the jsp:getProperty action.

Note that the class specified for the bean must be in the server's regular class path, not the part reserved for classes that get automatically reloaded when they change. For example, in the Java Web Server, it and all the classes it uses should go in the classes directory or be in a jar file in the lib directory, not be in the servlets directory.

Here is a very simple example that loads a bean and sets/gets a simple String parameter.

BeanTest.jspYou can also download the source or try it on-line. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>

<HEAD>

<TITLE>Reusing JavaBeans in JSP</TITLE>

<LINK REL=STYLESHEET

HREF="My-Style-Sheet.css"

TYPE="text/css">

</HEAD>

<BODY>

<CENTER>

<TABLE BORDER=5>

<TR><TH CLASS="TITLE">

Reusing JavaBeans in JSP</TABLE>

</CENTER>

<P>

<jsp:useBean id="test" class="hall.SimpleBean" />

<jsp:setProperty name="test"

property="message"

value="Hello WWW" />

<H1>Message: <I>

<jsp:getProperty name="test" property="message" />

</I></H1>

</BODY>

</HTML>

SimpleBean.javaHere's the source code for the bean used in the BeanTest JSP page. You can also download the source. package hall;

public class SimpleBean {

private String message = "No message specified";

public String getMessage() {

return(message);

}

public void setMessage(String message) {

this.message = message;

}

}

Here's a typical result:

8.3 More jsp:useBean DetailsThe simplest way to use a bean is to use

<jsp:useBean id="name" class="package.class" />

to load the bean, then use jsp:setProperty and jsp:getProperty to modify and retrieve bean properties. However, there are two other options. First, you can use the container format, namely

<jsp:useBean ...>

Body

</jsp:useBean>

to indicate that the Body portion should be executed only when the bean is first instantiated, not when an existing bean is found and used. As discussed below, beans can be shared, so not all jsp:useBean statements result in a new bean being instantiated. Second, in addition to id and class, there are three other attributes that you can use: scope, type, and beanName. These attributes are summarized in the following table.

Atribute

Usage

id

Gives a name to the variable that will reference the bean. A previous bean object is used instead of instantiating a new one if one can be found with the same id and scope.

class

Designates the full package name of the bean.

scope

Indicates the context in which the bean should be made available. There are four possible values: page, request, session, and application. The default, page, indicates that the bean is only available on the current page (stored in the PageContext of the current page). A value of request indicates that the bean is only available for the current client request (stored in the ServletRequest object). A value of session indicates that the object is available to all pages during the life of the current HttpSession. Finally, a value of application indicates that it is available to all pages that share the same ServletContext. The reason that the scope matters is that a jsp:useBean entry will only result in a new object being instantiated if there is no previous object with the same id and scope. Otherwise the previously existing object is used, and any jsp:setParameter elements or other entries between the jsp:useBean start and end tags will be ignored.

type

Specifies the type of the variable that will refer to the object. This must match the classname or be a superclass or an interface that the class implements. Remember that the name of the variable is designated via the id attribute.

beanName

Gives the name of the bean, as you would supply it to the instantiate method of Beans. It is permissible to supply a type and a beanName, and omit the class attribute.

8.4 The jsp:setProperty ActionYou use jsp:setProperty to give values to properties of beans that have been referenced earlier. You can do this in two contexts. First, you can use jsp:setProperty after, but outside of, a jsp:useBean element, as below: <jsp:useBean id="myName" ... />

...

<jsp:setProperty name="myName"

property="someProperty" ... />

In this case, the jsp:setProperty is executed regardless of whether a new bean was instantiated or an existing bean was found. A second context in which jsp:setProperty can appear is inside the body of a jsp:useBean element, as below: <jsp:useBean id="myName" ... >

...

<jsp:setProperty name="myName"

property="someProperty" ... />

</jsp:useBean>

Here, the jsp:setProperty is executed only if a new object was instantiated, not if an existing one was found.

There are four possible attributes of jsp:setProperty:

Attribute

Usage

name

This required attribute designates the bean whose property will be set. The jsp:useBean element must appear before the jsp:setProperty element.

property

This required attribute indicates the property you want to set. However, there is one special case: a value of "*" means that all request parameters whose names match bean property names will be passed to the appropriate setter methods.

value

This optional attribute specifies the value for the property. String values are automatically converted to numbers, boolean, Boolean, byte, Byte, char, and Character via the standard valueOf method in the target or wrapper class. For example, a value of "true" for a boolean or Boolean property will be converted via Boolean.valueOf, and a value of "42" for an int or Integer property will be converted via Integer.valueOf. You can't use both value and param, but it is permissible to use neither. See the discussion of param below.

param

This optional attribute designates the request parameter from which the property should be derived. If the current request has no such parameter, nothing is done: the system does not pass null to the setter method of the property. Thus, you can let the bean itself supply default values, overriding them only when the request parameters say to do so. For example, the following snippet says "set the numberOfItems property to whatever the value of the numItems request parameter is, if there is such a request parameter. Otherwise don't do anything." <jsp:setProperty name="orderBean"

property="numberOfItems"

param="numItems" />

If you omit both value and param, it is the same as if you supplied a param name that matches the property name. You can take this idea of automatically using the request property whose name matches the property one step further by supplying a property name of "*" and omitting both value and param. In this case, the server iterates through available properties and request parameters, matching up ones with identical names.

Here's an example that uses a bean to create a table of prime numbers. If there is a parameter named numDigits in the request data, it is passed into the bean's numDigits property. Likewise for numPrimes.

JspPrimes.jspTo download the JSP source, right click on the source code link. You can also download the source code for the NumberedPrimes bean referenced by the jsp:useBean element. Browse the source code directory for other Java classes used by NumberedPrimes. The best way to try it out on-line is to start with the HTML page that acts as a front end to it. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>

<HEAD>

<TITLE>Reusing JavaBeans in JSP</TITLE>

<LINK REL=STYLESHEET

HREF="My-Style-Sheet.css"

TYPE="text/css">

</HEAD>

<BODY>

<CENTER>

<TABLE BORDER=5>

<TR><TH CLASS="TITLE">

Reusing JavaBeans in JSP</TABLE>

</CENTER>

<P>

<jsp:useBean id="primeTable" class="hall.NumberedPrimes" />

<jsp:setProperty name="primeTable" property="numDigits" />

<jsp:setProperty name="primeTable" property="numPrimes" />

Some <jsp:getProperty name="primeTable" property="numDigits" />

digit primes:

<jsp:getProperty name="primeTable" property="numberedList" />

</BODY>

</HTML>

Here's a typical result:

8.5 The jsp:getProperty ActionThis element retrieves the value of a bean property, converts it to a string, and inserts it into the output. The two required attributes are name, the name of a bean previously referenced via jsp:useBean, and property, the property whose value should be inserted. Here's an example; for more examples, see Sections 8.2 and 8.4. <jsp:useBean id="itemBean" ... />

...

<UL>

<LI>Number of items:

<jsp:getProperty name="itemBean" property="numItems" />

<LI>Cost of each:

<jsp:getProperty name="itemBean" property="unitCost" />

</UL>

8.6 The jsp:forward ActionThis action lets you forward the request to another page. It has a single attribute, page, which should consist of a relative URL. This could be a static value, or could be computed at request time, as in the two examples below. <jsp:forward page="/utils/errorReporter.jsp" />

<jsp:forward page="<%= someJavaExpression %>" />

8.7 The jsp:plugin ActionThis action lets you insert the browser-specific OBJECT or EMBED element needed to specify that the browser run an applet using the Java plugin.

9. Comments and Character Quoting ConventionsThere are a small number of special constructs you can use in various cases to insert comments or characters that would otherwise be treated specially. Here's a summary:

Syntax

Purpose

<%-- comment --%>

A JSP comment. Ignored by JSP-to-scriptlet translator. Any embedded JSP scripting elements, directives, or actions are ignored.

<!-- comment -->

An HTML comment. Passed through to resultant HTML. Any embedded JSP scripting elements, directives, or actions are executed normally.

<\%

Used in template text (static HTML) where you really want "<%".

%\>

Used in scripting elements where you really want "%>".

\'

A single quote in an attribute that uses single quotes. Remember, however, that you can use either single or double quotes, and the other type of quote will then be a regular character.

\"

A double quote in an attribute that uses double quotes. Remember, however, that you can use either single or double quotes, and the other type of quote will then be a regular character.

%\>

%> in an attribute.

<\%

<% in an attribute.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有