<< Chapter < Page Chapter >> Page >

The list of names

Listing 7 provides a line of introductory text for the list of names to be displayed on the screen. The first time the form appears on the screen,the value stored in the name variable is null, and the word Empty is displayed as shown in Figure 1 . Later on after multiple requests, the list will be populated as shown in Figure 2 .

Listing 7 - Beginning of the list of names.
out.println("<p>Your list of names is:<br/>"); if(name == null){out.println("Empty</p>"); }//end if

Create new hidden fields for historical data

Listing 2 retrieved all of the data in the hidden fields on the form and saved that data in a String array named items .

If that array contains data, the code in Listing 8 performs two actions using the data from each of the elements in the array:

  • Display the historical data stored in those element of the array.
  • Create new hidden fields in the HTML output form under construction and place the data values from the array in those hidden fields.
Listing 8 - Display the historical data and also save it on the browser.
if(items != null){ for(int i = 0; i<items.length; i++){ //Display names previously saved in hidden fieldsout.println(items[i] + "<br/>"); //Save the names in hidden fields on form currently// under construction. out.println("<input type=\"hidden\" name=\"item\" " + "value=\"" + items[i]+ "\">"); }//end for loop}//end if

Limited persistence

Thus, the historical data is passed forward from the hidden fields of one HTML form to the hidden fields of the next HTML form. All of the historical dataresides on the HTML form in the browser cache in the client computer. However, that is not a location that provides long-term persistence, so this scheme forsession tracking has limited persistence.

Create new hidden field for new data

Listing 3 retrieved the field value submitted by the browser and saved that value in a variable named name .

If that variable contains data, the fragment in Listing 9 performs two actions using the data stored in the variable.

  • Display the value at the end of the list of names.
  • Create a new hidden field in the HTML output form under construction and place the value from the variable in that hidden field.
Listing 9 - Display most recent value and also store it on the browser.
if(name != null){ //Display name submitted with current GET requestout.println(name + "<br/>"); //Save name submitted with current GET request in a // hidden field on the form currently under// construction out.println("<input type=\"hidden\" name=\"item\" " + "value=\"" + name + "\">"); }//end if

Thus, for each new request by the browser, one additional hidden field is added to the HTML form under construction. The new hidden field contains thefield value submitted by the browser.

The remaining servlet code

The remainder of the code for the servlet is typical of what you have seen before and can be viewed in the complete listing of the servlet in Listing 16 .

Questions & Answers

the diagram of the digestive system
Assiatu Reply
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
cell is the building block of life.
Condoleezza Reply
what is cell divisoin?
Aron Reply
Diversity of living thing
ISCONT
what is cell division
Aron Reply
Cell division is the process by which a single cell divides into two or more daughter cells. It is a fundamental process in all living organisms and is essential for growth, development, and reproduction. Cell division can occur through either mitosis or meiosis.
AI-Robot
What is life?
Allison Reply
life is defined as any system capable of performing functions such as eating, metabolizing,excreting,breathing,moving,Growing,reproducing,and responding to external stimuli.
Mohamed
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