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

Taking Some Medication - 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.

TABLE OF CONTENTS:
  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
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
Just as you can access data from text fields, you can also use the getParameter() method to evaluate the state of radio buttons and list boxes. Suppose you modify the form above to something a little more complex.




<html> <head> <basefont face="Arial"> </head> <body> <center> <form method="GET" action="pills.jsp"> <font size="-1" face="Arial"> Gimme <select name="quantity"> <option value="10">10</option> <option value="25">25</option> <option value="50">50</option> <option value="100">100</option> </select> of those little <input type="Radio" name="colour" value="red" checked>red <input type="Radio" name="colour" value="blue">blue pills, willya? </font> <p> <input type="Submit"> </form> </center> </body> </html>

And here's "pills.jsp".

<html><head><basefont face="Arial"></head><body><center><%// pills.jsp// define the variables and assign valuesString colour = request.getParameter("colour");String quantity_string = request.getParameter("quantity");// convert string to numberint quantity = Integer.parseInt(quantity_string);// process and display// who needs green pills?if (colour.equals("blue")){out.println("Sorry, we don't carry blue pills here.");}else{ if (quantity >= 50) { out.println("Stocking up, are we?"); } else { out.println("Here you go. And would you like fries with that?"); }}%></center></body></html>
Depending on the combination of pill type and quantity, an appropriate message will be displayed.

As you can see, evaluating radio buttons and list boxes is almost exactly the same as evaluating regular text fields.

Before moving on to the other form constructs - namely, checkboxes and multiple-select list boxes - you need to understand a new type of variable: the JSP array.

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

JAVA & J2EE ARTICLES

- 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: