• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet question

 
Rajeev Nair
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iam trying to compile an example of password protected page from chapter 4 of "core servlets and jsp" . The servlet ProtectedPage reads a password file which is created in another class called PasswordBuilder. My question is that the PasswordBuilder can be in any place or it should be in one of the tomcat directory to access this file?. Iam getting an nullpointer exception for it.
I have put the password file in PasswordBuilder class like
String passwordFile =
"C:\\servletdevel\\source\\passwords.properties";
Let me know what iam doing wrong.
Thanks in advance
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The PasswordBuilder can be in any place in the file system. Remember to create all foldres in the filepath before runing PasswordBuilder.
I've just run the sample direct from the book...
/Rene
[ July 06, 2002: Message edited by: Rene Larsen ]
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your file could be anywhere, as long as you specify the complete pathe to the file.
 
Rajeev Nair
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rene,
Thanks for your reply ,but i didnt get when you say "Remember to create all foldres in the filepath before runing PasswordBuilder". Can you elaborate on this. Thanks in advance.
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The filepath must exist otherwise you'll get an exception.
In your example the folders 'servletdevel' and 'source' must exist.
/Rene
 
Rajeev Nair
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rene,
I compiled PasswordBuilder and now my question is where should the class file be placed. I tried by placing the class file in the tomcat directory and also in the same servlet/source directory ,but both time when i tried to run gave me an nullpointer exception. Any idea will be appreciated.
Thanks
 
Baruch Sadogursky
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to your code you try to access properties file, not class.
Anyway, when you'll change it put the class file in yourWebApp/WEB-INF/classes
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way you run this sample is:
First run PasswordBuilder, it doesn't matter from where you do it. It will generate a password file in the location specified in the code

Next step it to configure the webserver to read the password file by getting the location with 'config.getInitParameter(passwordFile)'.
In the web.xml you configure the servlet like this:

You can now call the servlet like this:
http://127.0.0.1/ProtectedPage
/Rene
[ July 08, 2002: Message edited by: Rene Larsen ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic