Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Servlet question

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic