Simple servlet help - please

Advertisement
November 30

I am trying to write a simple servlet that based on the client ip redirect to a new page.
I can get the client ip and return it. But what I am not sure how to do next is to take that ip address and search through the text file and return the second field (i.e abc.html)
I have setup a text file that is tab delimmited that looks like the following:
XXX.XXX.XXX.XXX abc.html
XXX.XXX.XXX.123 apps/index.html
Any suggestions greatly appreciated.

Advertisement

Replay

A simple solution:
Format your file correctly and use it as a properties file.(Take a look at the Properties Class: http://java.sun.com/j2se/1.4/docs/api/java/util/Properties.html )
To check the values, load your file as a Properties:
  public static final String PATH_OF_THE_FILE = "textFile.properties";
  private Properties props;
    InputStream sFile= null;
    try
      sFile= ClassLoader.getSystemResourceAsStream(PATH_OF_THE_FILE );
      props = new Properties();
      props.load(sFile);
      sFile.close();
    }catch(Throwable t){...}..and ask for the property you need:
String value= props.getProperty(theIP);Another solution would be to load your ip/url pairs into a static HashMap (check HashMap class: http://java.sun.com/j2se/1.4/docs/api/java/util/HashMap.html )
HTH

View 2 Replies

Tags:

  1. what hv to do after stolen kaptop
  2. segment e1idku4
  3. BAPI_OUTB_DELIVERY_CREATE_STO
  4. dullzwf
  5. negativex5u
  6. 2M6M
  7. suddenlyki9
  8. TH8D
  9. wintery8y
  10. grainoh6
Copyrights 2019 Fcffair BigData Resource, All rights reserved