• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Applet to Servlet Communication (only two ways?)

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All the examples that I've seen about Applet to servlet communication is in two ways, I mean it always has to be from the applet to the servlet and from the servlet to the applet.

My problem is that in my project I have to send some data to the Servlet and then the Servlet has to take the controll of everything, it isn't necesary to return to the applet, instead the Servlet has to make a mapping.findforward to another action....

If what I want to do is possible, please give some ideas about this....
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
read a book on servlets.


thanks & regards.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What examples are you working from?
Are you sending serialised java objects in a HTTP request from applet to servlet?
This is what I do in my code:



The last three lines are to receive a response from the servlet. In my case this is also serialised java objects. Are you saying you don't want to receive a response? Maybe you could just drop these last 3 lines. Not sure.
 
Ramiro Veramendi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your answers...

well this is what I have in my applet:

URL urlServlet = new URL("http://localhost:8080/triad/test.do");
URLConnection con = (URLConnection) urlServlet.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestProperty("Content-Type","application/x-java-serialized-object");
// send data to the servlet
OutputStream outstream = con.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(outstream);
oos.writeObject(template.getTemplate());
oos.flush();
oos.close();
// receive result from servlet
ObjectInputStream inputFromServlet = new ObjectInputStream(con.getInputStream());
Object result = (Object) inputFromServlet.readObject();
inputFromServlet.close();

And this is what I have in my Servlet:

response.setContentType("application/x-java-serialized-object");
//from the applet
InputStream in = request.getInputStream();
ObjectInputStream inputFromApplet = new ObjectInputStream(in);
Object template = (Object) inputFromApplet.readObject();
//to the Applet
OutputStream outstr = response.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(outstr);
oos.writeObject(respuesta);
oos.flush();
oos.close();

return mapping.findForward("successTemplate");


So this code works fine, I mean that I can send what ever I want from the applet to the servlet, and I can send also what ever from the Servlet to the applet...

But what I want is "....just to send something to the Servlet and then the servlet take the control", but in this scheme what is happening is when something is send to the Servlet the servlet gives the control again to the applet, and the conexion finish in the applet, and not in the Servlet.

I tried to erase the last 3 lines to recieve the response from the Servlet, and also i Tried to erase the code from the Applet, but when some "conexion code" from the applet and also from the Servlet is miss, the program gives the next exception:

If I erase the code to return something to the applet from the Servlet:
//to the Applet
OutputStream outstr = response.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(outstr);
oos.writeObject(respuesta);
oos.flush();
oos.close();

I got the follow error:

java.io.EOFException
at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source)
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)....................................

and if I erase the code to retrive something from the Servlet from the Applet:
// receive result from servlet
ObjectInputStream inputFromServlet = new ObjectInputStream(con.getInputStream());
Object result = (Object) inputFromServlet.readObject();
inputFromServlet.close();

"I can't retrieve anything from the Applet.........."

so, my question is that is it possible to have the applet to servlet communication just in one way (...just Applet --> Servlet)
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, you can not do that. In fact I had also come across to the same situation. What I found is that you have to redirect or forward from calling applet/servlet only.

Originally posted by Ramiro Veramendi:
so, my question is that is it possible to have the applet to servlet communication just in one way (...just Applet --> Servlet)

 
reply
    Bookmark Topic Watch Topic
  • New Topic