You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Sandra Patricia Hunter <re...@shaw.ca> on 2003/03/27 19:26:23 UTC

Registering Servlets

In the web.xml file I need to include init params Like this:
    <init-param>
    	<param-name>
    		passwordFile
    	</param-name>
    	<param-value>
    		C:\SANDRA\BC
Transit\IDCardProject\Passwords\passwords.properties
    	</param-value>
    </init-param> 

What I have done here, however, is wrong. Story of my life...

I am creating a passwordFile using a FileOutputStream to the address above
like this:		String passwordFile =
		  "C:\\SANDRA\\BC
Transit\\IDCardProject\\Passwords\\passwords.properties";
		FileOutputStream out = new FileOutputStream(passwordFile);

However when I call it like this:
      passwordFile = config.getInitParameter("passwordFile");
      passwords = new Properties();
      passwords.load(new FileInputStream(passwordFile)); 

The above web.xml does not do the trick. I believe my param-name is correct,
but what should the value be?  

Sandra Patricia Hunter
Systems Development and Web Design 
 



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Registering Servlets

Posted by Justin Ruthenbeck <ju...@nextengine.com>.
At 11:04 AM 3/27/2003, you wrote:
>Sandra Patricia Hunter wrote:
>
>>What happens is that when I enter what should be correct username/password
>>pairs they are not recognized. The value above for the name passwordFile is
>>not correct so I do not see the page as I should.
>>Does that help?
>
>Are you sure that it's a matter of reading the init-param?  I'd try 
>printing out the value of that init-param from your servlet with code 
>similar to this in doGet():
>
>   String name = "passwordFile";
>   String value = this.getServletConfig(
>                              ).getInitParameter(name);
>   PrintWriter out = resp.getWriter();
>   out.println("<h1>The value of " + name + " is " + value + "</h1>");
>
>This will tell you whether or not it's a problem with your web.xml file or 
>if it's your bidness logic.

When dealing with pure java like you are here, it's generally a good idea 
to setup your file path names like this:

C:/home/whatever/webapp/passwords.props

instead of using the escaped slashes.  Java will convert this to your 
OS-specific path separator *if* you are specifying a file that the JVM will 
load.  I suspect that if you do what Erik suggested above, you'll find that 
your initparam is something like this:

c:\home\whatever\webapp\passwords.props

which, when given to the FileOutputStream, will result in a search for a 
file named:

c:/ome/hatever/ebapp/asswords.props

that (probably) ;)  doesn't exist.

justin

____________________________________
Justin Ruthenbeck
Software Engineer, NextEngine Inc.
justinr - AT - nextengine DOT com
Confidential
    See http://www.nextengine.com/confidentiality.php
____________________________________


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Registering Servlets

Posted by Sandra Patricia Hunter <re...@shaw.ca>.
Interesting idea but no. Still I have to enter the password three times and
then it just lets me in. Weird. Value of realPassword is still null.
Something is not talking to something else. But what??

Sandra Patricia Hunter
Systems Development and Web Design 
 


-----Original Message-----
From: p niemandt [mailto:maudib@acesurfer.co.za] 
Sent: March 27, 2003 1:37 PM
To: 'Tomcat Users List'
Subject: RE: Registering Servlets


hi,

Here's an idea: Don't know of the relevance, but have you tried with an
actual password, or a password of blank - "" -> Maybe the problem is that
during the uploading, your password is being converted to a blank, or zero
length string, which would not be the same as a null string.

Just an idea.
Paul

On Thu, 2003-03-27 at 21:07, Sandra Patricia Hunter wrote:
> Well I am finding the file but something else is up: I can enter the 
> password three times and it rejects it and then lets me in after the 
> third time anyway. The real password value is null. I guess I need to 
> do more research into the base64 stuff.
> 
> Sandra Patricia Hunter
> Systems Development and Web Design
>  
> 
> 
> -----Original Message-----
> From: Erik Price [mailto:eprice@ptc.com]
> Sent: March 27, 2003 12:04 PM
> To: Tomcat Users List
> Subject: Re: Registering Servlets
> 
> 
> 
> 
> Sandra Patricia Hunter wrote:
> > Four
> > 
> 
> Yep, I ended up finding it (<http://pdf.coreservlets.com/>) -- I agree
> with Justin that it's probably the way you're specifying your file path. 
>   Remember that even on Windows, it's easier to use Unix-style file 
> paths in Java.  (Think of it as writing your code not for Windows but 
> for the Java virtual machine.)  Try changing it as he suggests and see 
> if that makes the difference.
> 
> 
> Erik
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
-- 
p niemandt <ma...@acesurfer.co.za>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Registering Servlets

Posted by p niemandt <ma...@acesurfer.co.za>.
hi,

Here's an idea: Don't know of the relevance, but have you tried with an
actual password, or a password of blank - "" -> Maybe the problem is
that during the uploading, your password is being converted to a blank,
or zero length string, which would not be the same as a null string.

Just an idea.
Paul

On Thu, 2003-03-27 at 21:07, Sandra Patricia Hunter wrote:
> Well I am finding the file but something else is up: I can enter the
> password three times and it rejects it and then lets me in after the third
> time anyway. The real password value is null.
> I guess I need to do more research into the base64 stuff.
> 
> Sandra Patricia Hunter
> Systems Development and Web Design 
>  
> 
> 
> -----Original Message-----
> From: Erik Price [mailto:eprice@ptc.com] 
> Sent: March 27, 2003 12:04 PM
> To: Tomcat Users List
> Subject: Re: Registering Servlets
> 
> 
> 
> 
> Sandra Patricia Hunter wrote:
> > Four
> > 
> 
> Yep, I ended up finding it (<http://pdf.coreservlets.com/>) -- I agree 
> with Justin that it's probably the way you're specifying your file path. 
>   Remember that even on Windows, it's easier to use Unix-style file 
> paths in Java.  (Think of it as writing your code not for Windows but 
> for the Java virtual machine.)  Try changing it as he suggests and see 
> if that makes the difference.
> 
> 
> Erik
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
-- 
p niemandt <ma...@acesurfer.co.za>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Registering Servlets

Posted by Sandra Patricia Hunter <re...@shaw.ca>.
Well I am finding the file but something else is up: I can enter the
password three times and it rejects it and then lets me in after the third
time anyway. The real password value is null.
I guess I need to do more research into the base64 stuff.

Sandra Patricia Hunter
Systems Development and Web Design 
 


-----Original Message-----
From: Erik Price [mailto:eprice@ptc.com] 
Sent: March 27, 2003 12:04 PM
To: Tomcat Users List
Subject: Re: Registering Servlets




Sandra Patricia Hunter wrote:
> Four
> 

Yep, I ended up finding it (<http://pdf.coreservlets.com/>) -- I agree 
with Justin that it's probably the way you're specifying your file path. 
  Remember that even on Windows, it's easier to use Unix-style file 
paths in Java.  (Think of it as writing your code not for Windows but 
for the Java virtual machine.)  Try changing it as he suggests and see 
if that makes the difference.


Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Registering Servlets

Posted by Erik Price <ep...@ptc.com>.

Sandra Patricia Hunter wrote:
> Four
> 

Yep, I ended up finding it (<http://pdf.coreservlets.com/>) -- I agree 
with Justin that it's probably the way you're specifying your file path. 
  Remember that even on Windows, it's easier to use Unix-style file 
paths in Java.  (Think of it as writing your code not for Windows but 
for the Java virtual machine.)  Try changing it as he suggests and see 
if that makes the difference.


Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Registering Servlets

Posted by Sandra Patricia Hunter <re...@shaw.ca>.
Four

Sandra Patricia Hunter
Systems Development and Web Design 
 


-----Original Message-----
From: Erik Price [mailto:eprice@ptc.com] 
Sent: March 27, 2003 11:19 AM
To: Tomcat Users List
Subject: Re: Registering Servlets




Sandra Patricia Hunter wrote:
> Well, it's printing out the value I assign in the web.xml file. Still 
> it is not recognizing the user/password pairs. I think that I don't 
> have the correct value but I don't know what correct would be?
> 
> I am using the code from Marty Hall's core servlets book called 
> protectedPage, and it should be straightforward but not.

What chapter?


Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Registering Servlets

Posted by Erik Price <ep...@ptc.com>.

Sandra Patricia Hunter wrote:
> Well, it's printing out the value I assign in the web.xml file.
> Still it is not recognizing the user/password pairs. I think that I don't
> have the correct value but I don't know what correct would be?
> 
> I am using the code from Marty Hall's core servlets book called
> protectedPage, and it should be straightforward but not. 

What chapter?


Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Registering Servlets

Posted by Sandra Patricia Hunter <re...@shaw.ca>.
Well, it's printing out the value I assign in the web.xml file.
Still it is not recognizing the user/password pairs. I think that I don't
have the correct value but I don't know what correct would be?

I am using the code from Marty Hall's core servlets book called
protectedPage, and it should be straightforward but not. 

Sandra Patricia Hunter
Systems Development and Web Design 
 


-----Original Message-----
From: Erik Price [mailto:eprice@ptc.com] 
Sent: March 27, 2003 11:05 AM
To: Tomcat Users List
Subject: Re: Registering Servlets




Sandra Patricia Hunter wrote:

> What happens is that when I enter what should be correct 
> username/password pairs they are not recognized. The value above for 
> the name passwordFile is not correct so I do not see the page as I 
> should.
> 
> Does that help?

Sort of.  I mean, I understood the nature of the problem, but wasn't 
sure if you were getting an exception or compiler error.

Are you sure that it's a matter of reading the init-param?  I'd try 
printing out the value of that init-param from your servlet with code 
similar to this in doGet():


   String name = "passwordFile";
   String value = this.getServletConfig(
                              ).getInitParameter(name);
   PrintWriter out = resp.getWriter();
   out.println("<h1>The value of " + name + " is " + value + "</h1>");

This will tell you whether or not it's a problem with your web.xml file 
or if it's your bidness logic.

Also, not sure if you fully stopped and started Tomcat...


Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Registering Servlets

Posted by Erik Price <ep...@ptc.com>.

Sandra Patricia Hunter wrote:

> What happens is that when I enter what should be correct username/password
> pairs they are not recognized. The value above for the name passwordFile is
> not correct so I do not see the page as I should.
> 
> Does that help?

Sort of.  I mean, I understood the nature of the problem, but wasn't 
sure if you were getting an exception or compiler error.

Are you sure that it's a matter of reading the init-param?  I'd try 
printing out the value of that init-param from your servlet with code 
similar to this in doGet():


   String name = "passwordFile";
   String value = this.getServletConfig(
                              ).getInitParameter(name);
   PrintWriter out = resp.getWriter();
   out.println("<h1>The value of " + name + " is " + value + "</h1>");

This will tell you whether or not it's a problem with your web.xml file 
or if it's your bidness logic.

Also, not sure if you fully stopped and started Tomcat...


Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Registering Servlets

Posted by Sandra Patricia Hunter <re...@shaw.ca>.
Hi Erik:
This is my web.xml:
    <servlet>
      <servlet-name>ProtectedPage</servlet-name>
      <description>
        this is the first menu for the application
      </description>
      <servlet-class>idcard.ProtectedPage</servlet-class>
  	<init-param>
		<param-name>
			passwordFile
		</param-name>
		<param-value>
			Passwords
		</param-value>
    	</init-param>
    </servlet>

What happens is that when I enter what should be correct username/password
pairs they are not recognized. The value above for the name passwordFile is
not correct so I do not see the page as I should.

Does that help?

Sandra Patricia Hunter
Systems Development and Web Design 
 


-----Original Message-----
From: Erik Price [mailto:eprice@ptc.com] 
Sent: March 27, 2003 10:43 AM
To: Tomcat Users List
Subject: Re: Registering Servlets




Sandra Patricia Hunter wrote:

[...]

> I am creating a passwordFile using a FileOutputStream to the address above
> like this:		String passwordFile =
> 		  "C:\\SANDRA\\BC 
> Transit\\IDCardProject\\Passwords\\passwords.properties";
> 		FileOutputStream out = new FileOutputStream(passwordFile);
> 
> However when I call it like this:
>       passwordFile = config.getInitParameter("passwordFile");
>       passwords = new Properties();
>       passwords.load(new FileInputStream(passwordFile));
> 
> The above web.xml does not do the trick. I believe my param-name is 
> correct, but what should the value be?

You have to stop and then start Tomcat when you want the web.xml to be 
re-read.  Also, you didn't mention the error or problem you're getting?


Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Registering Servlets

Posted by Erik Price <ep...@ptc.com>.

Sandra Patricia Hunter wrote:

[...]

> I am creating a passwordFile using a FileOutputStream to the address above
> like this:		String passwordFile =
> 		  "C:\\SANDRA\\BC
> Transit\\IDCardProject\\Passwords\\passwords.properties";
> 		FileOutputStream out = new FileOutputStream(passwordFile);
> 
> However when I call it like this:
>       passwordFile = config.getInitParameter("passwordFile");
>       passwords = new Properties();
>       passwords.load(new FileInputStream(passwordFile)); 
> 
> The above web.xml does not do the trick. I believe my param-name is correct,
> but what should the value be?  

You have to stop and then start Tomcat when you want the web.xml to be 
re-read.  Also, you didn't mention the error or problem you're getting?


Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org