Solved

Interacting with a web page

Posted on 2008-10-28
6
312 Views
Last Modified: 2012-08-13
Hi,

So I have a java applet, I want it to open up a URL, which has a text input box. I want to post some text into it, "hit" a button, then parse the output page. Here is an example:

http://www.pandorabots.com/pandora/talk?botid=a841d6e81e36b78f

basically I want my applet to paste a chat message in there, submit the form, then parse the output to get the response from the chat bot. How would I go about doing this?

Thanks
0
Comment
Question by:DJ_AM_Juicebox
  • 3
  • 3
6 Comments
 
LVL 5

Expert Comment

by:zmo
ID: 22823043
have a look at : http://www.devx.com/Java/Article/17679/0/page/3

where they suggest a solution and an API to do so... never tried it though
0
 

Author Comment

by:DJ_AM_Juicebox
ID: 22823805
Ok that article looks promising, but how do I know the POST request to construct? I basically want to act as if I'm submitting a string from that edit field when the user hits the "Say" button.
0
 
LVL 5

Accepted Solution

by:
zmo earned 500 total points
ID: 22824298
well, you take the html source and all you'll have to set up is :

botcust2=974e6beb1e3b14df
message=<your text string>

it's equivalent to the "?botcust2=974e6beb1e3b14df&message=my%20message" you find in GET methods. The destination page is the same page.
[...]

<form method="POST" name="f">

<input type="HIDDEN" name="botcust2" value="974e6beb1e3b14df">

<table border="0" cellspacing="0">

<tr><td>

<input type="TEXT" autocomplete="off" name="message" size=60>

</td><td>&nbsp;</td><td>

<input type="SUBMIT" value="Say">

</td></tr><tr><td align="right" valign="top"><font size="-1">

<i>Powered by <a href="http://www.pandorabots.com" target="_blank">Pandorabots</a>.</i></font></td></tr></table>

</form>

[...]

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:DJ_AM_Juicebox
ID: 22824717
Ok so those would be the parameters to the request right? In that article I guess it would go something like:

    ClientHttpRequest h = new ClientHttpRequest();
    h.setParameter("botcust2", "974e6beb1e3b14df");
    h.setParameter("message",  "hi there how are you?");

But that object wants a URL in the constructor, I'm not sure what to use - for instance, when I'm looking at the page through a browser, it has this URL:

    http://www.pandorabots.com/pandora/talk?botid=a841d6e81e36b78f

is that what I use?

Finally, it should return an InputStream, after calling post(). How would I get the value as a String? Something like:

    InputStream is = h.post();
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));


Thanks
0
 
LVL 5

Expert Comment

by:zmo
ID: 22824836
about the URL I guess it is what you said...
But there's only one way to know for sure, it's to try.

about the reading of the page, what you say seems logical to me.
I never could memorize all the Reader mess in java, so do like I'd do : read the reference doc ;)
0
 

Author Comment

by:DJ_AM_Juicebox
ID: 22825133
Ok now that I see what's going on, this works perfectly:

    http://www.exampledepot.com/egs/java.net/Post.html

Thanks for helping me through it. Yeah I can never memorize the java IO classes.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Error with Java/Cache JDBC Classpath 2 30
Java Server Faces parameter pass? 6 37
servlet  URL Rewriting 1 24
ForLoop Example 3 40
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now