aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes How do I respond to a webpage that contains a javascript? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "How do I respond to a webpage that contains a javascript?" Watch "How do I respond to a webpage that contains a javascript?" New topic
Author

How do I respond to a webpage that contains a javascript?

Mal James
Greenhorn

Joined: Aug 08, 2009
Posts: 5
Hi All,
I am trying to write a Java standalone app (not an applet) that reads a webpage across the net and then responds to it (with a user and password on the first page).
I have got as far as creating an HttpsURLConnection, connecting to it, reading from it and printing the resulting page source which includes a <SCRIPT> tag. Now I want to send something ( a page? a PUT? Run a javascript that sends stuff? I don't know what ) back to the server.

As far as I can see, when the page is displayed in a browser, the script sends the user and password values from the screen back to the server. I have the user and password values available in the app but don't know what to do with them.

I have spent the morning trying to get direction for the next move ( Eg. I found Rhino and jQuery but they seem server-oriented and overkill ). Maybe I just need a subset???

Can anyone point me in the right direction as to how I buld up and send a response? That is, I know how to getOutputStream() and write to it but I don't know what to write.
Should I be trying to run the javascript script from Java (if so how?) or just doing some kind of 'POST' back to the server (if so what format?)?

Sorry for asking about what has clearly been done a million times before but I am going in Googlic circles at the moment.
All constructive comments gratefully received.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60082
    
  65

You need to bone up on how HTTP works. I've moved this to a more appropriate location.

In HTTP, when you send the request for the page to the server, it responses by sending you the body of the HTML page as its response. That transaction is not done, You do not respond to it it any way. If you want to talk to the server again, you do so with another request.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mal James
Greenhorn

Joined: Aug 08, 2009
Posts: 5
Thank you, sorry for abusing the boffins' forum.

Could you pass some clues on how I pass a second request that looks (to the server) as if it came from the javascript that the server just sent me?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
The Apache HttpClient library makes this relatively easy (there are lots of examples on its web site), as does the HtmlUnit library.


Ping & DNS - updated with new look and Ping home screen widget
Mal James
Greenhorn

Joined: Aug 08, 2009
Posts: 5
Thank you Ulf, I will have a look at the httpClient.
 
 
subject: How do I respond to a webpage that contains a javascript?
 
Similar Threads
what streams to use for inputing and outputing an character array over a socket
About the book
Multiple submissions
Passing values to and from HTML
NT login - triggered by Java App