Gidday, I've been going through Marty Hall's CoreServlets book which has an example of a protected page servlet, which uses a properties file for checking the passwords. I can't seem to get the servlet to work. I have done the following:- 1) Created the properties file using the book's program PasswordBuilder.java 2) This has created a properties file in the following directory as shown below:- c:\tomcat\webapps\ROOT\WEB-INF\classes\coreservlets\passwords.properties 3) I then add the following to the the web.xml file located in the WEB-INF directory as follows:- <servlet> <servlet-name> ProPage </servlet-name> <servlet-class> coreservlets.ProtectedPage </servlet-class> <init-param> <param-name> passwordFile </param-name> <param-value> "passwords.properties" </param-value> </init-param> </servlet> 4) Placed the ProtectedPage.class file into the directory above 5) Started up Tomcat server 6) Started up browser and gone to address:- http://localhost/servlet/coreservlets/ProtectedPage 7) The tomcat error page comes up with an error trace which points to the third code line in ProtectedPage.java shown below:- String passwordFile = config.getInitParameter("passwordFile"); Properties passwords = new Properties(); passwords.load(new FileInputStream(passwordFile)); What is the matter? Where should the passwords.properties file be placed? How should this be entered in the web.xml file? Any help would be much appreciated! Regards
chanoch wiggers
Author
Ranch Hand
Joined: May 24, 2001
Posts: 245
posted
0
my guess is that you are getting IOException; File cannot be found? we need to see the stack trace to give you a confident answer.
chanoch<p><a href="http://www.amazon.com/exec/obidos/ASIN/1861007736/" target="_blank" rel="nofollow">Author of Professional Apache Tomcat</a></p>
Frank Carver
Sheriff
Joined: Jan 07, 1999
Posts: 6913
posted
0
It looks like you have two problems. 1. you don't need the " characters around the name of the properties file in the web.xml, remove them. 2. you should put the properties file in the WEB-INF/classes directory itself, not in a subdirectory. Try that and let us know how you get on.
Thanks for the info so far. I have taken the " " out, and placed the properties file in the classes directory as suggested. Unfortunately I seem to be getting a NullPointerException as shown in the following stack trace:-Exception report message Internal Server Error description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request. exception java.lang.NullPointerException at java.io.File.(File.java:180) at java.io.FileInputStream.(FileInputStream.java:66) at coreservlets.ProtectedPage.init(ProtectedPage.java:32) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:852) at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:615) at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:396) at org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:180) at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243) at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201) at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566) at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246) at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2344) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170) at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170) at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462) at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163) at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1011) at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1106) at java.lang.Thread.run(Thread.java:536) Any ideas? Thanks,
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12266
1
posted
0
Looking at line 180 in File I see that is what happens when you pass a null instead of a file name. I bet your init method is not doing what you think it is. Bill