Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Jakarta Server Pages
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Directives, scriptlets, and expressions, declaration === JSPs use several delimiters for [[server-side scripting|scripting]] functions. The most basic is <code> <% ... %></code>, which encloses a JSP ''scriptlet.'' A scriptlet is a fragment of Java code{{sfn | Murach | Urban | 2014 | loc=Β§2 Essential servlet and JSP skills - How to use JSP tags | pp=180-182}} that runs when the user requests the page. Other common delimiters include <code> <%= ... %></code> for ''expressions,'' where the scriptlet and delimiters are replaced with the result of evaluating the expression, and ''directives'', denoted with <code><%@ ... %></code>.{{sfn | Murach | Urban | 2014 | loc=Β§2 Essential servlet and JSP skills - How to use JSP tags | pp=180-182}}<ref name="syntax">[http://www.oracle.com/technetwork/java/syntaxref12-149806.pdf JSP 1.2 Syntax Reference]</ref> Java code is not required to be complete or self-contained within a single scriptlet block. It can straddle markup content, provided that the page as a whole is syntactically correct. For example, any Java ''if/for/while'' blocks opened in one scriptlet must be correctly closed in a later scriptlet for the page to successfully compile. This allows code to be intermingled and can result in poor programming practices. Content that falls inside a split block of Java code (spanning multiple scriptlets) is subject to that code. Content inside an ''if'' block will only appear in the output when the ''if'' condition evaluates to true. Likewise, content inside a loop construct may appear multiple times in the output, depending upon how many times the loop body runs. ==== Example ==== The following would be a valid [[for loop]] in a JSP page: <syntaxhighlight lang="jsp"><p>Counting to three:</p> <% for (int i=1; i<4; i++) { %> <p>This number is <%= i %>.</p> <% } %> <p>OK.</p> </syntaxhighlight> The output displayed in the user's web browser would be: <pre> Counting to three: This number is 1. This number is 2. This number is 3. OK. </pre>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Jakarta Server Pages
(section)
Add topic