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  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Forums Sitemap 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
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? 
Google.com  
JAVA

The JSP Files (part 4): The Red Pill
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    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

    - Exception Handling Techniques in Java
    - More About Multithreading in Java
    - The Basics of Multiple Threads in Java
    - Data Access Using Spring Framework JDBC
    - New Object Initialization in Java
    - 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...



     



    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek