my dog learned polymorphism
The moose likes Java in General and the fly likes how to enter password once, in code, for url database access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to enter password once, in code, for url database access" Watch "how to enter password once, in code, for url database access" New topic

how to enter password once, in code, for url database access

joyita raksit

Joined: Oct 12, 2006
Posts: 17
hey there,

i'm writing a program that needs to access details from a secure web server, it's basically person data drawn from a database that is displayed on a webpage. you are prompted to enter a password, but once you've entered the password, you pull up as many details as you like. (fully authorised to do this by the way!)

i intend to simply modify the end part of the url - looking like - .../address.asp?Mem_id=34812 - changing the number to pull up different records thru the program. once i've done this, i'm using java to convert the html and then process as xml to enter into another database. my problem is - i'm not sure exactly how to write the code for the password to be entered, here's the bit where it's going wrong...

public static void main(String args[]) {
try {
Document doc = XMLHelper.tidyHTML("http://www.********/********/address.asp?Mem_id=34812");
XMLHelper.outputXMLToFile(doc, "XML" + File.separator + "sudet.xml");
} catch (XMLHelperException xmle) {

the xml output gives me the "please enter password" page - not the info - even tho i've enetered the password seperately on the same machine. i'm guessing its something to do with ports?

could anyone give me a hint about what i need to be looking at to complete this bit of code? i've seen to servlets pop up on my searches??

thanks for reading so far, hope i've made myself clear!
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
This has nothing to do with ports. The fact that you entered the password in a browser is irrelevant for the Java application. The connection from the Java client also needs to set the password. I don't know how the helper classes you use retrieve HTML, but if there is a (or one of its subclasses) involved somewhere, then the way to do it is described here. If not, study the API of the classes you use to see if there is a way to set the password.
joyita raksit

Joined: Oct 12, 2006
Posts: 17

(i've mispelled Kookie on purpose as it wont let me post with right spelling)

i'm thinking of taking up the url connection solution, i'm currently trying to use jakarta httpclient - which enables you to set kookies, but i keep getting a - package org.apache.commons.httpclient does not exist - error, even tho i have it installed & its dependancies!

here's my code:

& here's the classpath:

C:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\Program Files\Java\jdk1.6.0\bin;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Java\jdk1.6.0\bin;C:\Program Files\Java\jdk1.6.0\bin\Tidy.jar;C:\Program Files\Java\jdk1.6.0\bin\xerces.jar;C:\Program Files\Java\jdk1.6.0\bin\xercesSamples.jar;C:\Program Files\Java\jdk1.6.0\bin\serializer;C:\Program Files\Java\jdk1.6.0\bin\xalan.jar;C:\Program Files\Java\jdk1.6.0\bin\xercesImpl.jar;C:\Program Files\Java\jdk1.6.0\bin\xml-apis.jar;C:\Program Files\Java\jdk1.6.0\bin\xsltc.jar;C:\Program Files\Java\jdk1.6.0\bin\jaxen-jdom;C:\Program Files\Java\jdk1.6.0\bin\jaxen-core;C:\Program Files\Java\jdk1.6.0\bin\saxpath.jar;C:\Program Files\Java\jdk1.6.0\bin\ant.jar; C:\Program Files\Java\jdk1.6.0\bin\commons-httpclient-3.1-beta1.jar;C:\Program Files\Java\jdk1.6.0\bin\commons-logging-api-1.1.jar;C:\Program Files\Java\jdk1.6.0\bin\commons-logging-adapters-1.1.jar;C:\Program Files\Java\jdk1.6.0\bin\commons-logging-1.1.jar;C:\Program Files\Java\jdk1.6.0\bin\commons-codec-1.3.jar;C:\Program Files\Java\jdk1.6.0\bin\junit.jar

i just cant see where i'm going wrong here... any ideas? if not, i'll have to give up on this train & go for the url connection one which does look good & i'm going to investigate anyway, thanks a lot for the cogent help
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
I notice that in your classpath, just before the httpclient entry, there seems to be some whitespace. Not sure whether that's the problem, but you might want to investigate in that direction...

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
joyita raksit

Joined: Oct 12, 2006
Posts: 17

oh. my. god.
it was the whitespace!!!
Ilja, you are my hero, thank you!
I agree. Here's the link:
subject: how to enter password once, in code, for url database access
jQuery in Action, 3rd edition