java类库详细讲解
源代码在线查看: if.html
Implementing Conditional Content on a JSP Page
(Java Developers Almanac Example)
BODY CODE {font-family: Courier, Monospace; font-size: 11pt} TABLE, BODY {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt} PRE {font-family: Courier, Monospace; font-size: 10pt} H3 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11pt} A.eglink {text-decoration: none} A:hover.eglink {text-decoration: underline} -->
The Java Developers Almanac 1.4
Order this book from Amazon.
Home
>
List of Packages
>
javax.servlet.jsp
[18 examples]
>
Java Server Pages Output
[4 examples]
e1058.
Implementing Conditional Content on a JSP Page
Any non-JSP code in a JSP file is called template text and is
automatically written to the output stream. By wrapping template text
fragments in scriptlets, it is possible to dynamically choose which
fragment to generate.
These examples generate different template text depending on
the value of request parameters:
<% if ("someValue".equals(request.getParameter("param1"))) { %>
Generate this template text if param1 equals someValue
<% } else { %>
Otherwise generate this template text
<% } %>
<% switch (Integer.parseInt(request.getParameter("param2"))) {
case 0: %>
Generate this template text if param2 equals 0
<% break;
case 1: %>
Generate this template text if param2 equals 1
<% break;
default: %>
Generate this template text if param2 equals anything else
<% } %>
See also e1068 Conditionally Generating Output Using JSTL in a JSP Page.
Related Examples
e1056.
Commenting a JSP Page
e1057.
Generating Dynamic Content on a JSP Page
e1059.
Handling Unhandled Exceptions in a JSP Page
See also:
Java Server Pages
Java Server Pages Headers
Java Server Pages Input
© 2002 Addison-Wesley.