Okay, this probably seems a little backwards. I know tons of people have posted about, and information is readily available about, how to read data from forms onto your servlet.
But, I have a different problem. I have a servlet that I'm running. Elsewhere on the web, there is a website that has a little box where you can enter a sentence for parsing. It parses the sentence, and then returns the parsed sentence. I need to parse a sentence, and that website is perfect for the job. The problem is, the servlet for that webapp is written in python.
In java, it'd be relatively easy. The text field on the form for this other website is named "theText". So, if it were in java, I'd simply get my servlet, open a urlConnection with the website's address and append to that address: "?theText=whateverSentenceIWantToParse" to it, and send it on it's way. Then, I'd parse what it sent back for the sentence I wanted.
But, I can't seem to do that with this python-based website. When I try to do that, it expects the field "theText" to be in a dictionary, not as a single parameter floating out there in space. So, how do I fill out that form information, or, how do I format the URL?
Hope the question is clear, and thanks for the help
If I were you, I would check how the HTML-page of the application is built and what parameters etc. are sent (by the way, did you URL-encode the URL you are calling in your application?).
In addition, you can check how the HTTP-communication is structured (e. g. with the LiveHTTPHeaders-Plugin in Firefox) when you call the target application in your web browser. This should give you insights about what parameters are sent and how they are transmitted to the target system.
Afterwards you should try to rebuild this structure manually with your HttpUrlConnection.
The form that I entered the sentence into looked like:
<form method = 'post' action = '/classifier/text/text/>
<textarea name = "text"></textarea><input type= "submit" value = "Classify">
then it goes on with some optional fields that I don't care about before closing the form.
So, the task seems simple enough. I just want to POST data to the website 'host/classifier/text/text/', giving the parameter "text" the value of the sentence I want it to parse. But, I'm not sure how to do this. I looked at HttpURLConnection, but I don't see any methods in it for actually sending data.
Any advice from here?
subject: sending information from a servlet to form