wood burning stoves*
The moose likes Servlets and the fly likes Servlet question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet question" Watch "Servlet question" New topic
Author

Servlet question

Rajeev Nair
Ranch Hand

Joined: Mar 11, 2002
Posts: 51
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


Raj<br />Sun Certified Java Programmer
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

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 ]

Regards, Rene Larsen
Dropbox Invite
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Your file could be anywhere, as long as you specify the complete pathe to the file.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Rajeev Nair
Ranch Hand

Joined: Mar 11, 2002
Posts: 51
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

Joined: Oct 12, 2001
Posts: 1179

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

Joined: Mar 11, 2002
Posts: 51
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

Joined: Apr 09, 2002
Posts: 62
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


Regards,<br />Baruch.<p>SDFWOF<br />FGEHWS<br />FNEVGE
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

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 ]
 
Don't get me started about those stupid light bulbs.
 
subject: Servlet question
 
Similar Threads
Retrive a single data from database and display that in jsp text box.
urgent-problem in accessing initialisation parameters
cannot access ms access database after loading servlet to tomcat
JSP problem..
Connection with servlets (jsp)