Simple servlet help - please

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.



A simple solution:
Format your file correctly and use it as a properties file.(Take a look at the Properties Class: )
To check the values, load your file as a Properties:
  public static final String PATH_OF_THE_FILE = "";
  private Properties props;
    InputStream sFile= null;
      sFile= ClassLoader.getSystemResourceAsStream(PATH_OF_THE_FILE );
      props = new Properties();
    }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: )

View 2 Replies


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