aspose file tools*
The moose likes Servlets and the fly likes urgent-problem in accessing initialisation parameters  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "urgent-problem in accessing initialisation parameters  " Watch "urgent-problem in accessing initialisation parameters  " New topic
Author

urgent-problem in accessing initialisation parameters

preeti dengri
Ranch Hand

Joined: Nov 30, 2000
Posts: 111
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
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12836
    
    5
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:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: urgent-problem in accessing initialisation parameters