Books
in black and white
Main menu
Home About us Share a book
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

Java Server your visual Blueprint to Design Dynamic Content - Whitehead P.

Whitehead P. Java Server your visual Blueprint to Design Dynamic Content - Wiley Publishing, 2001. - 133 p.
Download (direct link): yourtodesigningdynamic2001.pdf
Previous << 1 .. 21 22 23 24 25 26 < 27 > 28 29 30 31 32 33 .. 117 >> Next

ADD A COMMENT TO A JSP PAGE
Untitled - Notepad
File Edit Search Help
String siteName = "My Web Site"; public String stars(int x)
{
String message = M*M; for (int i = B; i < x; i**) message = message + " return message;
>
<html>
<head>
<!--|Created Feb 15 20011 >1 ^title>My JSP Page</title> </head>
<body>
<h1>
Welcome to <%= siteName %><br> <%= stars(20) %>
</h1>
</body>
</html>
D To add an HTML
comment, type <!.
' ype the comment.
Type > to complete the HTML comment.
Untitled - Notepad
File Edit Search Help
<%*
String siteName = "My Web Site";
public String stars(int x)
String message = ;
for (int i = 0; i < x; i++) message = message + return message;
>
%>
<html>
<head>
<* Created Feb 15 2001 > <title>My JSP Page</title> </head>
<body>
----
n_
<X Display a welcome messagel%>| Welcome to <7a= siteName ^><Dr>
<%= stars(20) %>
</h1>
</body>
</html>
~ To add a hidden comment, type <%.
Type the comment.
Q Type --%> to complete the hidden comment.
64
GETTING STARTED WITH JAVASERVER PAGES
3
I <%! String siteName = "My Web Site"; %> 1
<html>
<head>
<!-- The variable siteName has a value of
"<%= siteName %>" -->
<title>My JSP Page</title>
</head>
<body>
<% siteName = "* " + siteName + " *"; %>
<!-- The variable siteName has a value of
"<%= siteName %>" -->
Welcome to <%= siteName %><br>
</body>
</html>
?a My JSP Page - Microsoft Internet Explorer
~
J File Edit View Favorites Tools Help
1 @1 ?el} | ^Search fla Favorites i3 History | *
I'i-
Address |SJ http:t!\ 27.0.0.1:3030/examples/comment.js
?~] | j Links :
Welcome to My Web Site
*********************
Q Save the page with the .jsp extension and then display the page in a Web browser.
| | | Internet
3 My JSP Page - Microsoft Internet Explorer Je]*|
J File Edit View Favorites Tools Help
j Back - ^ ' ' 0 ?aH Search [^Favorites 0History | ^ 3 T @ J3. ?
J Address 1 comment[1 ] - Notepad 0 rGo I Links H
File Edit Search Help 3
Welc * * * * <htnl> <head> 3
1 <! Created Feb 15 2001 >|
<title>Mi( JSP Page</title> </head> <body> <h1>
Welcome to My Web Site<br>
</h1> </body> </html> d
zi
If] Done JJ Internet
? The comments do not affect the display of the JSP page.
Q Display the source code of the JSP page.
The HTML comment is included in the HTML
source code, but the hidden comment does not appear.
65
? JSP


CREATE AN EXPRESSION
An expression is a scripting element that allows you to generate output on a JSP page. You can use expressions to insert information into a Web page rather than using scriptlets with out .print () or out .println () statements. This reduces the amount of code you have to type and can make your scripts easier to read.
The Web server processes the code within the expression and converts the results to a string. The results of the expression are then inserted into the HTML code in the same manner as the result of out. print () and out .println () statements in scriptlets.
A simple expression can be used to display a string enclosed in quotation marks or the value of a variable.
The Web server simply inserts the string or value into the HTML code. Variables must be declared and initialized in scriptlets or declarations in the same JSP page.
You can also use calculations and method calls in your expressions. The expression processes the calculation
or method and inserts the result into the HTML code. Methods used in expressions must be declared in the same JSP page and return a printable value. If a method does not return a value, the Web server displays an error message.
You can use string concatenation to join different types of information in a single expression.
For example, you can create an expression such as <%= "Date of Birth: " + getDOBQ %>, which generates a string followed by the value returned by a method.
An expression cannot end with a semicolon, as is customary with most Java statements. If a semicolon is included in an expression, an error will occur.
Users viewing the source code of the Web page from within a Web browser will not be able to view the contents of the expression. They will see only the information generated by the expression.
CREATE AN EXPRESSION
Untitled - Notepad
File Edit Search Help
<%* String pgTitle <html>
<head>
<title>
I-
"My JauaSeruer Page"; %>
<7title>
</head>
<body>
<h1>
Welcome to </h1> </body> </html>
-D Type <%= where you want to insert an expression in the JSP page.
Untitled - Notepad
File Edit Search Help
String pgTitle = "My JauaSeruer Page"; X> <htnl>
<head>
<title>
<%=|pgTitle| %>
<body>
<h1>
Welcome to </h1> </body> </html>
0 Type %> where you want the expression to end.
Between the opening and closing delimiters (<%= and %>), type the code to be evaluated and included in the HTML code.
66
GETTING STARTED WITH JAVASERVER PAGES
3
String fontFace = "comic";
<%= "<font face=\"" + fontFace + "\">My Web Page</font>" %> <%= "<br>c:\\Tomcat" %>
Previous << 1 .. 21 22 23 24 25 26 < 27 > 28 29 30 31 32 33 .. 117 >> Next