Java Reference
In-Depth Information
Programming Assignments
1 A Web Page Greeting in JavaScript
Create a Web page that displays a greeting along with the current date, similar
to Figure 12-93. Use only HTML and JavaScript to create the Web page. Obtain
the current date with JavaScript by defining a variable and assigning a new Date
object, as in
var today = new Date();
Save the Web page code as Greeting.html and then copy it to the Tomcat default
root folder, or a location specified by your instructor. Start a browser and type
http://localhost:8080/Greeting.html in the address text box. Print the page
when it is displayed in the browser.
FIGURE 12-93
2 A Web Page Greeting in a Servlet
Create a Web page identical to the one created in Programming Assignment 1
using only a servlet to create the Web page. Import java.util.Date in order to
create a Date object. Constructing a default Date object obtains the current date,
as in
Date today = new Date();
Print the servlet code. Compile the servlet and copy the class file to the Tomcat
default servlet folder, or a location specified by your instructor. After starting
Tomcat, start a browser and type http://localhost:8080/servlet/Greet-
ingServlet in the address text box. Print the page when it is displayed in the
browser.
Search WWH ::




Custom Search