How do I convert http calls into https calls in Applet.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Shiva_dacherla
Posted On:   Friday, November 9, 2001 03:46 PM

Hi,


I am working on Applet-Servlet communication. I have working code inplace between Applet-Servlet communication. Now I would like to make it to change to https.Any sample code is appreciated or any suggestions please.



Thanks
Shiva

Re: How do I convert http calls into https calls in Applet.

Posted By:   Guanglin_du  
Posted On:   Wednesday, March 20, 2002 11:16 PM

Dear Shiva,

I hope that my answer is not late and still helpful to you. The following code fragment is what I'm using to carry out the applet-servlet comminication in my project:


import java.net.*;

import java.io.*;

String location = "http://dgl:8080/ripedbs/servlet/";

// 03/07/2002, reads the input data

//Applet-servlet communication(valid only once per request)03/21/2002

try {

URL testServlet = new URL(location + "MeshServlet?myMesh");
URLConnection servletConnection = testServlet.openConnection();

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

servletConnection.setDoOutput(true);
servletConnection.setDoInput(true);

// Don't use a cached version of URL connection.

servletConnection.setUseCaches(false);

servletConnection.setDefaultUseCaches(false);

//POSTs the request data (html form encoded).


PrintStream out = new PrintStream(servletConnection.getOutputStream());

out.println(URLEncoder.encode("mesh")+"="+URLEncoder.encode("WireFrame"));

out.close();

//Reads the POST response data

InputStream in = servletConnection.getInputStream();

// InputStreamReader inReader = new InputStreamReader(in);

int i = in.read();

while (i != -1) {

System.out.print((char) i);

i = in.read();
}

in.close();

System.out.println("Successfully read from the servlet response");

} catch (Throwable t) {

t.printStackTrace();

}

where MeshServlet is a servlet on my server side. Notice that the applet-servlet communication
is valid only once per request, that is, you can have the applet commumicate with the servlet only
once(including writing ONLY once to (POST) the servlet and reading ONLY once from the servlet!).
Two or more efforts from the same instance of the applet to try to comminicate with the servlet won't work.

Best wishes!
About | Sitemap | Contact