Results 1 to 1 of 1
Thread: applet servlet communication
- 04-06-2009, 01:12 PM #1
Member
- Join Date
- Apr 2009
- Posts
- 1
- Rep Power
- 0
applet servlet communication
I have been working with applet servlet communication through web browser as a interface.i got strucked with a problem,
here s my applet code,
private URLConnection getServletConnection()
throws MalformedURLException, IOException {
// Connection zum Servlet öffnen
URL urlServlet = new URL(getCodeBase(), "echo");
URLConnection con = urlServlet.openConnection();
// konfigurieren
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestProperty(
"Content-Type",
"application/x-java-serialized-object");
// und zurückliefern
return con;
}
URLConnection con = getServletConnection();
OutputStream outstream = con.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(outstream);
oos.writeObject(input);
oos.flush();
oos.close();
// receive result from servlet
InputStream instr = con.getInputStream();
ObjectInputStream inputFromServlet = new ObjectInputStream(instr);
String result = (String) inputFromServlet.readObject();
inputFromServlet.close();
instr.close();
and here s my servlet code
response.setContentType("application/x-java-serialized-object");
// read a String-object from applet
// instead of a String-object, you can transmit any object, which
// is known to the servlet and to the applet
InputStream in = request.getInputStream();
ObjectInputStream inputFromApplet = new ObjectInputStream(in);
String echo = (String) inputFromApplet.readObject();
// echo it to the applet
OutputStream outstr = response.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(outstr);
oos.writeObject(echo);
oos.flush();
oos.close();
it works fine,when applet sends a string object to servlet through ObjectOutputStream and servlet recieve it and responses the string object to applet and applet recieved that string object too...but after after applet recieved the string object from servlet, it process on that string and it tried to send that string object back to servlet,it s not working...
here is that applet code am getting problem
URLConnection con = getServletConnection();
OutputStream outstream = con.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(outstream);
oos.writeObject(input);
oos.flush();
oos.close();
// receive result from servlet
InputStream instr = con.getInputStream();
ObjectInputStream inputFromServlet = new ObjectInputStream(instr);
String result = (String) inputFromServlet.readObject();
inputFromServlet.close();
instr.close();
URLConnection con1 = getServletConnection();
OutputStream outstream1 = con.getOutputStream();
ObjectOutputStream oos1 = new ObjectOutputStream(outstream1);
oos1.writeObject(input);
oos1.flush();
oos1.close();/ i didnt this write object at servlet side......plz help me
thanks in advance
Similar Threads
-
Java Servlet and Web Service communication
By shussain@del.aithent.com in forum Java ServletReplies: 36Last Post: 03-16-2010, 07:28 PM -
Applet > servlet file transfer
By milkman128 in forum Java AppletsReplies: 1Last Post: 11-15-2008, 03:21 PM -
Jar and War communication in an Ear
By madanmohanp in forum Advanced JavaReplies: 1Last Post: 08-02-2008, 01:39 PM -
how to send and receive data from servlet to applet Continuously ??
By jega_ms in forum Java ServletReplies: 1Last Post: 01-28-2008, 10:49 AM -
applet servlet communication
By hardc0d3r in forum Java AppletsReplies: 1Last Post: 07-12-2007, 06:58 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks