• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Protected Page problem

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Con Lu
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic