Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Mal James
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64822
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mal James
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Apache HttpClient library makes this relatively easy (there are lots of examples on its web site), as does the HtmlUnit library.
 
Mal James
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ulf, I will have a look at the httpClient.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic