To make a poll form using an applet, i wanted to know how can my applet communicate with a servlet . That servlet is meant to write the result to the text file on the server. I have no idea how can i do this.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could use
java.net.URLConnectionfor this.Assuming that your servlet is mapped on an URL pattern of
/myservletand your applet is been served from the context root, then this should do:That’s all. The
getCodeBase()is inherited fromAppletclass and dynamically returns the applet’s code base URL (from where the applet was been downloaded). TheservletResponsewill contain whatever you wrote toresponse.getOutputStream()orresponse.getWriter()in the servlet. For example just an “ok” string or an easily parseable format like XML or JSON. You could pass request parameters as a query string in the GET request URL, or in the POST request body.See also: