• 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.


0
vilas32
Asked:
vilas32
1 Solution
 
sgomsCommented:
// 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
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);

// 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
servletConnection.setRequestProperty
             ("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
out.println("paramname="+data+"paramname2="+data2....);

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,
                  http://www.j-nine.com/pubs/applet2servlet/Applet2Servlet.html 
for more info.

-sgoms
0
 
vilas32Author Commented:
Thanks a lot sgom.
0

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