• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

Passing data from Applet to servlet

I have a JApplet which has around 10 JTextFields, JCheckBox, JRadioButtons,  JList, JComboBox, JTextAreas, JButtons etc. and I want to pass all the information entered on this JApplet to servlet. The servlet has to accept this data, update my database and  reply to applet with an acknowledgement which is displayed in a JTextArea on the applet.

I am able to get data from servlet to applet and display the data on applet.
But I am unable to pass the data from JApplet to servlet.

Please use example to describe your solution. What should I code in my Japplet and servlet so that servlet recieves data.

Thanks a lot for your help.

1 Solution
// connect to the servlet
String location = "http://www.foo.com/servlet/TestServlet";
URL testServlet = new URL( servletLocation );
URLConnection servletConnection = testServlet.openConnection();

// inform the connection that we will send output and accept //input

// Don't use a cached version of URL connection.
servletConnection.setUseCaches (false);
servletConnection.setDefaultUseCaches (false);

// Specify the content type that we will send binary data
             ("Content-Type", "<insert favorite mime type>");

// get input and output streams on servlet
PrintWriter out = new PrintWriter(servletConnection.getOutputStream());
inputStreamFromServlet = servletConnection.getInputStream();

// send your data to the servlet

what u need to do is get the values from ur textfileds,comboboxex,etc..have an appropriate paramname for it which can be retrived from the servlet using getParameter() & just pass it as a string in the out.println(..);

this is the POST method of sending data.

chk out,
for more info.

vilas32Author Commented:
Thanks a lot sgom.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now