• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

urgent-problem in accessing initialisation parameters

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
this is an example from Marty Hall's core servlets and java server pages for restricted access to web pages(listing 4.3).there is a helper class for making a simple java properties file containing usernames and passwords
import java.util.*;
import java.io.*;
public class passwordbuilder
{
public static void main(String args[]) throws Exception
{
Properties passwords =new Properties();
passwords.put("marty","martypw");
passwords.put("bj","bjpw");

String passwordfile="c:\\javawebserver2.0\\data\\passwords.properties";
FileOutputStream out=new FileOutputStream(passwordfile);
passwords.save(out,"Passwords");
}
}
when i am using tomcat , i gave the String passwordfile to be
String passwordfile="c:\\tomcat\\webapps\\webclient\\passwords.txt";
i tried it with passwords.properties in the String ,but my servlet is not working
the steps i took is:
1) created passwordbuilder.java
2)made necessary changes to web.xml as follows
<web-app>
<servlet>
<servlet-name>
protectedpage
</servlet-name>
<servlet-class>
protectedpage
</servlet-class>
<init-param>
<param-name>passwordfile/param-name>
<param-value>passwords.txt</param-value>
</init-param>
</servlet>


</web-app>
2)created protectedpage.java which access the init parameter "passwordfile" from web.xml file.
public void init(ServletConfig config) throws ServletException
{
super.init(config);
try
{
passwordfile=config.getInitParameter("passwordfile");
passwords=new Properties();
passwords.load(new FileInputStream(passwordfile));
}
catch(IOException e){}
}
please suggest the changes to be made.
thank you
preeti
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you will have to provide a complete path in:
<param-name>passwordfile/param-name>
<param-value>passwords.txt</param-value> <-- change this
The form you used for accessing the properties file:
passwordfile=config.getInitParameter("passwordfile");
passwords=new Properties();
passwords.load(new FileInputStream(passwordfile));
requires that the current directory be the one that has password.txt, but you can't rely on the current directory in a servlet situation - you must give a complete path.
Bill

------------------
author of:
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic