<< Chapter < Page Chapter >> Page >

The parameter values in milliseconds are first converted from String to long . Each of the long values is then used to instantiate a new Date object, which is displayed in the format shown in Figure 2 .

Listing 8 - Display date and time history.
if(items != null){ for(int i = 0; i<items.length; i++){ long millis = Long.parseLong(items[i]); out.println("" + new Date(millis) + "<br/>"); }//end for loop}//end if
(Hopefully you already understand the relationship between the overridden toString method of the Date class and the format resulting from passing a Date object's reference to the println method. If not, see Ap0005: Preface to OOP Self-Assessment and the modules following that one.)

Display the current date and time

Listing 4 obtained the current date and time in milliseconds and saved it in a variable named theDate . Listing 9 uses that value to instantiate and display a new Date object reflecting the current date and time.

Listing 9 - Display the current date and time.
out.println("" + new Date(theDate) + "<br/>"); out.println("</body></html>");//finish HTML page

Listing 9 also creates the HTML code necessary to finish the HTML page.

The JSP program

I will also discuss the JSP program named Java4560b.jsp in fragments. A complete listing of the program is provided in Listing 17 .

Interesting code fragments

Import necessary packages

Listing 10 shows the necessary import directives plus the beginning of the HTML page.

Listing 10 - Import necessary packages.
<%@ page import='java.util.*,java.io.*' %><html><head><title>Java4560b</title></head><body>

There's nothing new in Listing 10 with the possible exception of the formatof the import directives. The format is different from the format used in regular Java code. (See Listing 1 .)

Some packages are imported automatically

Recall from Java4307: Servlets and JSP that it is not necessary to import javax.servlet and javax.servlet.http . Those two packages are automatically imported by the JSP container on theserver. No page directive import settings are required for using the classes defined in these packages.

Get data from the old parameter string

Listing 11 shows the beginning of a scriptlet containing pure Java code.

Listing 11 - Get data from the old parameter string.
<% String parameters = "?";String[] items = request.getParameterValues("item");

The code in Listing 11 declares and initializes a String that will be used later to construct a new parameter string.

Listing 11 also gets and saves the values of all of the parameters from the old parameter string named "item" .

Construct a new parameter string

Listing 12 constructs a new parameter string containing the names and values of all the parameters named "item" in the old parameter string. (A parameter for the current date and time will be concatenated later.)

Listing 12 - Construct a new parameter string.

Missing Figure

Concatenate current date and time to the parameter string

Listing 13 gets the current date and time in milliseconds andconcatenates it to the new parameter string with the name "item" .

Questions & Answers

what is mutation
Janga Reply
what is a cell
Sifune Reply
how is urine form
Sifune
what is antagonism?
mahase Reply
classification of plants, gymnosperm features.
Linsy Reply
what is the features of gymnosperm
Linsy
how many types of solid did we have
Samuel Reply
what is an ionic bond
Samuel
What is Atoms
Daprince Reply
what is fallopian tube
Merolyn
what is bladder
Merolyn
what's bulbourethral gland
Eduek Reply
urine is formed in the nephron of the renal medulla in the kidney. It starts from filtration, then selective reabsorption and finally secretion
onuoha Reply
State the evolution relation and relevance between endoplasmic reticulum and cytoskeleton as it relates to cell.
Jeremiah
what is heart
Konadu Reply
how is urine formed in human
Konadu
how is urine formed in human
Rahma
what is the diference between a cavity and a canal
Pelagie Reply
what is the causative agent of malaria
Diamond
malaria is caused by an insect called mosquito.
Naomi
Malaria is cause by female anopheles mosquito
Isaac
Malaria is caused by plasmodium Female anopheles mosquitoe is d carrier
Olalekan
a canal is more needed in a root but a cavity is a bad effect
Commander
what are pathogens
Don Reply
In biology, a pathogen (Greek: πάθος pathos "suffering", "passion" and -γενής -genēs "producer of") in the oldest and broadest sense, is anything that can produce disease. A pathogen may also be referred to as an infectious agent, or simply a germ. The term pathogen came into use in the 1880s.[1][2
Zainab
A virus
Commander
Definition of respiration
Muhsin Reply
respiration is the process in which we breath in oxygen and breath out carbon dioxide
Achor
how are lungs work
Commander
where does digestion begins
Achiri Reply
in the mouth
EZEKIEL
what are the functions of follicle stimulating harmones?
Rashima Reply
stimulates the follicle to release the mature ovum into the oviduct
Davonte
what are the functions of Endocrine and pituitary gland
Chinaza
endocrine secrete hormone and regulate body process
Achor
while pituitary gland is an example of endocrine system and it's found in the Brain
Achor
what's biology?
Egbodo Reply
Biology is the study of living organisms, divided into many specialized field that cover their morphology, physiology,anatomy, behaviour,origin and distribution.
Lisah
biology is the study of life.
Alfreda
Biology is the study of how living organisms live and survive in a specific environment
Sifune
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?

Ask