Java Reference
In-Depth Information
3 A Web Page Greeting in a JavaServer Page
Create a Web page identical to the one created in Programming Assignment 1
using only a JavaServer Page to create the Web page. Import java.util.Date and
create a Date object as was done in Programming Assignment 2. Copy the JSP
file to the Tomcat default root folder or a location specified by your instructor.
After starting Tomcat, start a browser and type http://localhost:8080/
Greeting.jsp in the address text box. Print the page when it is displayed in the
browser. Programming Assignments 1 through 3 display the same date and
approximate time when the local server is used as the host; however, if files from
Programming Assignments 2 and 3 were placed on a Web server other than the
local host, the displayed date and time could differ significantly. Write a
paragraph to explain why this could happen.
4 Creating HTML Forms in Java
Write a Java servlet, HTMLBank.java, that creates the HTML form as shown in
Figure 12-94. Use an instance variable for the balance. If the user enters a valid
amount in the Amount text box and then clicks the Deposit button, add the
amount to the balance; if the user clicks the Withdraw button, subtract the
amount from the balance. If no amount was entered, or if the amount is nega-
tive or zero, output a simple HTML page that displays an appropriate error mes-
sage. Compile the servlet and install it in the default servlet folder. Start Tomcat.
Start your Web browser, type http://localhost:8080/servlet/HTMLBank in
the address text box, and then press the ENTER key. To execute a second thread,
start another instance of your Web browser and load the servlet in it, as well.
Switching between the two instances, perform transactions with each. Recall that
an instance variable is shared among multiple threads. Write a short paragraph
that explains how the displayed balance verifies that the variable, balance, is
shared. Hint: Recall the use of a DecimalFormat to format numeric output. Use
the static method, Double.parseDouble(StringVariable), to convert the String
from the text box parameter, amount, to a double. Be sure that an amount was
entered before converting to a double.
Amount text box
formatted balance
Balance
button
Deposit
button
Withdraw
button
FIGURE 12-94
Search WWH ::




Custom Search