<< Chapter < Page Chapter >> Page >

Tedious and error prone

Writing raw HTML code is not fun even under the best of circumstances. That is why I use a WYSIWYG HTML editor for authoring these modules.

Even for this very simple servlet, the process of constructing the output HTML code using Java println statements was very tedious and error prone. Much of the difficulty arises from the fact that Java strings must be enclosed inmatching double quotes and all HTML attribute values must also be enclosed in matching double or single quotes. As you can see from Listing 16 , the requirement to escape double quotes inside Java strings with the backslashcharacter can lead to some very confusing code. (I suppose it might be less confusing if I were to use single quotes instead of double quotes on HTML attributevalues. I will try that in the next module.)

In any event, the next section presents a JSP version of the same servlet. JSP intermingles HTML code with Java code and greatly reduces the amount of HTMLcode that must be constructed using Java println statements in a servlet. If you are unfamiliar with JSP, you can learn about it in the modules that begin at Java4305: Preface to JSP .

The JSP program

A complete listing of the JSP version of this program is provided in Listing 17 . I found this JSP version much easier to write than the servlet version discussed above. Admittedly, however, I wrote the servlet version first, so that probablyhelped to make it easier to write the JSP version.

I wrote all of the HTML code using Microsoft Expression Web 4, which provides both a WYSIWYG capability and a raw HTML editing capability. Once I confirmed that theHTML code was correct and valid, I went back and inserted the JSP tags containing the Java code.

As mentioned earlier, the JSP does not get and use the name of the computer on which it is running. Instead it uses the generic name localhost, which limitsthe ability to access the JSP from another computer on the network.

Interesting code fragments

Once again, I will discuss this program in fragments. A complete listing of the program is provided in Listing 17 .

Create basic web page structure

Listing 10 shows the HTML code that is roughly equivalent to the Java code in Listing 4 through Listing 7 . This code creates the HTML header and the basic structure of the web page shownin Figure 1 .

Listing 10 - Create basic web page structure.
<html><head><title>Java4550a</title></head><body><form method="get" action="http://localhost:8080/Java4550a.jsp"><p>Enter a name and press the button</p><p>Name:<input type="text" name="firstName"/></p><input type="submit" value="Submit Name"/><p>Your list of names is:<br/>

A JSP scriptlet

Listing 11 is a scriptlet containing pure Java code. It begins by getting the data from the request object. Then it deals withthe situation where nothing has been entered into the text field in Figure 1 , reporting that the list is empty. It ends with the beginning of a for loop that is executed when the array is not empty. Recall that in JSP, Java code blocks can begin in one scriptlet andend in another scriptlet later in the page. That is what is happening here.

Questions & Answers

so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
how to fabricate graphene ink ?
for screen printed electrodes ?
What is lattice structure?
s. Reply
of graphene you mean?
or in general
in general
Graphene has a hexagonal structure
On having this app for quite a bit time, Haven't realised there's a chat room in it.
what is biological synthesis of nanoparticles
Sanket Reply
what's the easiest and fastest way to the synthesize AgNP?
Damian Reply
types of nano material
abeetha Reply
I start with an easy one. carbon nanotubes woven into a long filament like a string
many many of nanotubes
what is the k.e before it land
what is the function of carbon nanotubes?
I'm interested in nanotube
what is nanomaterials​ and their applications of sensors.
Ramkumar Reply
what is nano technology
Sravani Reply
what is system testing?
preparation of nanomaterial
Victor Reply
Yes, Nanotechnology has a very fast field of applications and their is always something new to do with it...
Himanshu Reply
good afternoon madam
what is system testing
what is the application of nanotechnology?
In this morden time nanotechnology used in many field . 1-Electronics-manufacturad IC ,RAM,MRAM,solar panel etc 2-Helth and Medical-Nanomedicine,Drug Dilivery for cancer treatment etc 3- Atomobile -MEMS, Coating on car etc. and may other field for details you can check at Google
anybody can imagine what will be happen after 100 years from now in nano tech world
after 100 year this will be not nanotechnology maybe this technology name will be change . maybe aftet 100 year . we work on electron lable practically about its properties and behaviour by the different instruments
name doesn't matter , whatever it will be change... I'm taking about effect on circumstances of the microscopic world
how hard could it be to apply nanotechnology against viral infections such HIV or Ebola?
silver nanoparticles could handle the job?
not now but maybe in future only AgNP maybe any other nanomaterials
I'm interested in Nanotube
this technology will not going on for the long time , so I'm thinking about femtotechnology 10^-15
can nanotechnology change the direction of the face of the world
Prasenjit Reply
At high concentrations (>0.01 M), the relation between absorptivity coefficient and absorbance is no longer linear. This is due to the electrostatic interactions between the quantum dots in close proximity. If the concentration of the solution is high, another effect that is seen is the scattering of light from the large number of quantum dots. This assumption only works at low concentrations of the analyte. Presence of stray light.
Ali Reply
the Beer law works very well for dilute solutions but fails for very high concentrations. why?
bamidele Reply
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Got questions? Join the online conversation and get instant answers!
QuizOver.com Reply

Get the best Algebra and trigonometry course in your pocket!

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?