Home arrow Java & J2EE arrow Page 7 - The JSP Files (part 4): The Red Pill

A Chocolate Addiction - Java

Now that the basics are done with, it's time to begin applyingthat theory to Web development. This week, The JSP Files investigates theJSP Request object, and demonstrates how it can be used to process formdata. Learn about JSP's array variables, find out what chocolate chipcookies and couch potatoes have in common, and explore a very unusualpharmacy.

  1. The JSP Files (part 4): The Red Pill
  2. The Last Action Hero
  3. Entering The Matrix
  4. Requesting More
  5. Taking Some Medication
  6. What's For Dessert?
  7. A Chocolate Addiction
  8. Couch Potato
  9. Beating It Into Submission
By: Vikram Vaswani, (c) Melonfire
Rating: starstarstarstarstar / 6
March 07, 2001

print this article


In order to modify an element of an array, you would simply assign a new value to the corresponding variable. If you wanted to replace "chocolate fudge cake" with "chocolate chip cookies", you'd simply use

<% desserts[3] = "chocolate chip cookies"; %>
and the array would now read

String[] desserts = {"chocolate mousse", "tiramisu", "apple pie", "chocolate chip cookies"};
JSP arrays can only store the type of data specified at the time of declaring the array variable; a string array cannot hold numbers, or vice-versa.

And finally, you can obtain the number of items in an array with the "length" property - the following example demonstrates this:

<html><head><basefont face="Arial"></head><body><%// define an arrayString[] desserts = {"chocolate mousse", "tiramisu", "apple pie","chocolate fudge cake"};// display array lengthout.println("The dessert menu contains " + desserts.length + " items."); %> </body></html>
And the output is:

The dessert menu contains 4 items.

You can use a "for" loop to iterate through the elements of an array, as the following example demonstrates.

<html><head><basefont face="Arial"></head><body>Desserts available:<ul><%// define counterint counter;// define an arrayString[] desserts = {"chocolate mousse", "tiramisu", "apple pie","chocolate fudge cake"};for (counter=0; counter<desserts.length; counter++){out.println("<li>" + desserts[counter] + "<br>");} %></ul></body></html>
And the output is:

Desserts available: - chocolate mousse- tiramisu- apple pie- chocolate fudge cake

>>> More Java & J2EE Articles          >>> More By Vikram Vaswani, (c) Melonfire

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates


Dev Shed Tutorial Topics: