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

Requesting More - 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


The Request object also comes with a bunch of other useful methods - the following example demonstrates some of them

<html> <head> <basefont face="Arial"> </head> <body> <table border="1" cellspacing="5" cellpadding="5"> <tr> <td><b>Variable</b></td> <td><b>Value</b></td> </tr> <tr> <td>Request protocol</td> <td> <% // protocol out.println(request.getProtocol()); %> </td> </tr> <tr> <td>Hostname</td> <td> <% // server name out.println(request.getServerName()); %> </td> </tr> <tr> <td>Port</td> <td> <% // server port out.println(request.getServerPort()); %> </td> </tr> <tr> <td>Remote username</td> <td> <% // username if using HTTP authentication // null if no authentication out.println(request.getRemoteUser()); %> </td> </tr> <tr> <td>Remote address</td> <td> <% // get IP address of client out.println(request.getRemoteAddr()); %> </td> </tr> <tr> <td>Client browser</td> <td> <% // client browser identification out.println(request.getHeader("User-Agent")); %> </td> </tr> </table> </body> </html>
And when you view the file in your browser, you'll probably see something like this:

Variable Value Request protocol HTTP/1.0Hostname localhostPort 80Remote username nullRemote address browser Mozilla/4.0 (compatible; MSIE 5.5; Windows 95)
All these variables come in handy if you need to make decisions on the basis of remote variables - as the following example demonstrates:

<% String browser = request.getHeader("User-Agent");if(browser.indexOf("MSIE") >= 0){ // IE-specific code}else if(browser.indexOf("Mozilla") >= 0){ // Mozilla-specific code}else{ // any other browser}%>
Note our usage of the indexOf() method - you may remember this from previous articles in this series.

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