CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 1999
    Location
    India.
    Posts
    81

    Applet Servlet Communication

    How to call a servlet from an applet and vice versa?


  2. #2
    Join Date
    Apr 2000
    Location
    Hyderabad, India
    Posts
    23

    Re: Applet Servlet Communication

    hai Monica,
    place all ur applet related files inside ur publichtml dir inside ur web server and servlet related files inside ur servlets directory and register the servlet inside the web server. the registrasion depends on the server u use.

    Then direcly call the applet from the browser using the ip and the applet name
    eg: http://localhost:8080/sample.html
    which ill refer to the applet in the publichtml dir and the applet ill call the servlet in the servlet directory as need the code u need to include in the applet is as given below :
    URL url = new URL(getCodeBase(),"/servlet/SampleServlet");
    HttpMessage msg = new HttpMessage(url);
    InputStream in = msg.sendGetMessage();
    DataInputStream result = new DataInputStream(new BufferedInputStream(in));
    String date = result.readLine();

    hope u got it.

    If u wanted further det. mail me at: [email protected]

    bye
    bharath



    S.V Bharath Reddy
    Software Engineer,
    Hyderabad.

  3. #3
    Join Date
    Apr 2000
    Location
    India (Gujarat)
    Posts
    12

    Re: Applet Servlet Communication

    Hi

    It is very simple. Write following code in your applet.

    URL urlobj=new URL("http://servername:8080/servlet/servletname");

    URLConnection urlcobj=urlobj.openConnection();

    InputStream in=urlcobj.getInputStream();

    //now you can customize the string and read from it. it will read what ever servlet writes.

    Now if you want to pass some parameters to the servlet do,

    append the parameters at the end of url string like this,

    http://localhost:8080/servlet/myserv?name=nirmit

    this will send a parameter named "name" and valued "nirmit" to the servlet.

    i the servlet you can fetch the parameter with string name=req.getparameter"name";

    That's all.

    mail me at [email protected] for further details.
    Good luck.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured