java left logo
java middle logo
java right logo
 

Home arrow Java SE Tips arrow java.applet arrow Access parameters passed in the URL
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 3942
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
Access parameters passed in the URL E-mail
User Rating: / 22
PoorBest 

This tip shows how to decode the parameters passed in the URL.

import java.applet.*;
import java.util.*;
public class SimpleApplet extends Applet {
 Hashtable searchparms;
 public void init() {
  // dump to the console the URL, the search and search values
  //  the URL  http://myserver.com/mypage.html?value1=x&value2=y&value3=z
  //  the search  value1=x&value2=y&value3=z
  //  the values  value1=x
  //              value2=y
  //              value3=z
  //
  // then the values are stored in a Hashtable for easy reference.
  // ex. String name = searchparms.get("value2")
  doit();
  }

 public void doit() {
  int i;
  String completeURL = getDocumentBase().toString();
  System.out.println("Complete URL: " + completeURL);
  i = completeURL.indexOf("?");
  if (i > -1) {
   String searchURL = completeURL.substring(completeURL.indexOf("?"1);
   System.out.println("Search URL: " + searchURL);

   StringTokenizer st =
     new StringTokenizer(searchURL, "&");
   while(st.hasMoreTokens()){
    String searchValue=st.nextToken();
    System.out.println("value :" + searchValue);
    }
   initHashtable(searchURL);
   dumpHashtable();
   }
  }

  public void initHashtable(String search) {
   searchparms = new Hashtable();
   StringTokenizer st1 =
     new StringTokenizer(search, "&");
   while(st1.hasMoreTokens()){
     StringTokenizer st2 =
       new StringTokenizer(st1.nextToken()"=");
     searchparms.put(st2.nextToken(), st2.nextToken());
     }
   }

  public void dumpHashtable() {
    Enumeration keys = searchparms.keys();
    System.out.println("--------");
    whilekeys.hasMoreElements() ) {
      String s = (Stringkeys.nextElement();
      System.out.println("key : " + s + " value : " + searchparms.get(s));
      }
    System.out.println("--------");
    }
 }

 Related Tips

 
Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.