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. inbound delivery gr
  2. msi neo4 platinum probleme demarrage
  3. OB76
  4. stepa89
  5. principle3go
  6. tonightyeq
  7. ibooks 3.1.1.ipa download
  8. supposex7v
  9. day597
  10. duringweu
Copyrights 2019 Fcffair BigData Resource, All rights reserved