send login and password to tomcat

S

seb

Hello! I want to protect a directory in my Web Application. Protected
directory: http://localhost:8080/sample/protected/ I did the necessary
things with the „tomcat-user.xml" and „web.xml" file. It works fine.
If the user wants to access a file in the protected directory, a
dialog appears and asks for login and password. With the right
login/password the user can access the files in this directory. But
what I have to do, if I want to access a file in this directory from a
Java program? Naturally a normal access returns a 401 Error code. How
can I send login/password from a Java program? I do not want, that a
dialog box appears.

Thanks

Sebastien
 
D

David Zimmerman

seb said:
Hello! I want to protect a directory in my Web Application. Protected
directory: http://localhost:8080/sample/protected/ I did the necessary
things with the „tomcat-user.xml" and „web.xml" file. It works fine.
If the user wants to access a file in the protected directory, a
dialog appears and asks for login and password. With the right
login/password the user can access the files in this directory. But
what I have to do, if I want to access a file in this directory from a
Java program? Naturally a normal access returns a 401 Error code. How
can I send login/password from a Java program? I do not want, that a
dialog box appears.

Two ways.
1 - put the userid/passwd into the URI. EG
http://user:passwd@localhost:8080/sample/protected

2 - Put the userid/passwd into the Authorization HTTP header. Study the
HttpURLConnection API to find out how.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top