• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

applet-servlet communication

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to use java.net package to realize the commnunication between applet and servlet, but my programe can't run well.
Help,please.
Thanks in advance.
codes as follows:

applet codes:
public class TestApplet extends Applet {
URL url;
URLConnection urlcon;
int hello;
public void init(){
try{
hello=111;
String link="http://localhost:8080/examples/servlet/TestServlet";
url=new URL(link);
urlcon = url.openConnection();
urlcon.setDoOutput(true);
urlcon.setDoInput(true);
urlcon.setUseCaches (false);
urlcon.setDefaultUseCaches (false);
DataOutputStream dos=new DataOutputStream(urlcon.getOutputStream());
dos.writeByte(hello);
dos.flush();
dos.close();
}catch(ProtocolException pe){
pe.printStackTrace();
}
catch(Exception e){
e.printStackTrace();
}
}
}
Servlet codes:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class TestServlet extends HttpServlet
{
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
doPost(request,response);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
System.out.println("hello");
DataInputStream in = new DataInputStream(request.getInputStream());
try {
int hello;
hello=in.readByte();
in.close();
System.out.println(" "+hello);
} catch (Exception exp) {
exp.printStackTrace();
}
}
}
 
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic