Java
  Home arrow Java arrow Page 4 - The JSP Files (part 4): The Red Pill
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

The JSP Files (part 4): The Red Pill
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 6
    2001-03-07

    Table of Contents:
  • The JSP Files (part 4): The Red Pill
  • The Last Action Hero
  • Entering The Matrix
  • Requesting More
  • Taking Some Medication
  • What's For Dessert?
  • A Chocolate Addiction
  • Couch Potato
  • Beating It Into Submission

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    The JSP Files (part 4): The Red Pill - Requesting More


    (Page 4 of 9 )

    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 192.168.0.143Client 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 Articles
    More By Vikram Vaswani, (c) Melonfire


     

       

    JAVA ARTICLES

    - Adding Images With iTextSharp
    - Adding Columns With iTextSharp
    - Creating Simple PDF Files With iTextSharp
    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...
    - Java Operators
    - Primitive Data Types and Basic Language Rule...
    - Java and Object-Oriented Programming
    - Java Beginning Programming
    - Gaming Development Setup

    BlackBerry VTS




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway