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