applet-servlet communication
hi,
i am doing a applet-servlet communication
my applet is sending name and number
i am able to sent the data from the applet but in the servlet i am not able to receive it
in my servlet i am using the following method
public void DoGet((HttpServletRequest req, HttpServletResponse res)
res.getParameter("name");
can some one tell me where am i going wrong ?
my applet source code is as follows
Applet Source
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==newbutton)
{
try
{
Properties args = new Properties();
String name="hi";
String number="hello";
args.put("name", name);
args.put("number", number);
URL newurl = new URL("http://localhost/servlet/DecryptNew");
InputStream result = sendMessage(args,POST,newurl);
// textarea.append(result);
//URLConnection conn = newurl.openConnection();
textarea.append("gone");
AppletContext context = getAppletContext();
context.showDocument(newurl,"_top");
/* URLConnection connect;
connect = (new URL("http://192.168.3.13/keytools/servlet/DecryptNew").openConnection();
connect.setDefaultUseCaches(false); //for future connections
connect.setUseCaches(false); //for this one
connect.setDoInput(true);
connect.setDoOutput(false);
connect.connect();
DataInputStream in = new DataInputStream(connect.getInputStream());
String response = in.readLine();
*/
}
catch(Exception ae){}
//URL newurl=new URL("http://192.168.3.13/keytools/servlet/DecryptNew");
// newurl.openconnection();
}
}
public InputStream sendMessage(Properties args, int method,URL newurl)
throws IOException
{
textarea.append(" i am here 1");
// Set this up any way you want -- POST can be used for all calls,
// but request headers cannot be set in JDK 1.0.2 so the query
// string still must be used to pass arguments.
if (method == GET) {
URL url = new URL(newurl.toExternalForm() + "?" +
toEncodedString(args));
return url.openStream();
} else {
URLConnection conn = newurl.openConnection();
textarea.append(" i am here 2");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
// Work around a Netscape bug
conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
// POST the request data (html form encoded)
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
if (args != null && args.size() > 0) {
out.writeBytes(toEncodedString(args));
System.out.println("ServletMessage args: " + args);
System.out.println("ServletMessage toEncString args: " + toEncodedString(args));
}
out.flush();
out.close(); // ESSENTIAL for this to work!
// Read the POST response data
return conn.getInputStream();
}
}
public String toEncodedString(Properties args) {
StringBuffer sb = new StringBuffer();
if (args != null) {
String sep = "";
Enumeration names = args.propertyNames();
while (names.hasMoreElements()) {
String name = (String)names.nextElement();
sb.append(sep + URLEncoder.encode(name) + "=" +
URLEncoder.encode(args.getProperty(name)));
sep = "&";
}
}
return sb.toString();
}

