• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Servlet » introduction » Applet to Servlet Communication
Next →
← Prev

Applet to Servlet Communication

By Dinesh Thakur

HTML exhibits high performance by taking less time to load in the browser. However, when we use HTML page for important user details, by default, all the parameters that are passed appended in the URL. This compromises with the security. On the other hand, applet takes more time to load but there is no problem with Java security. This is an advantage of this technique.

Applet is a compiled Java class that can be sent over the network. Applets are an alternative to HTML form page for developing websites. HTML form gives good performance, takes less time to load but has poor security. Whereas, Applets give poor performance, take time to load but have good security.

There are two types of Applets:

1. Untrusted Applets: It cannot interact with files and file system, so writing malicious codes is not possible. Applets are untrusted.

2. Trusted Applets: It can interact with files and file system so can write malicious codes.

                             Difference between applet and servlet

APPLET

SERVLET

Used to develop client side web-resource program to generate static web page.

Used to develop server side web-resource program to generate dynamic web-page.
Needs browser windw or appletviewer for execution.Needs servlet container for execution.
Applet program comes to browser window from server for execution.Servlet program reside and execute in web resource.
The life cycle methods are init(), start(), stop() and destroy().The life cycle methods are init(-), Service(-,-)  and destroy().

 Similar to HTML-to-servlet communication we need to perform applet-to servlet communication. In HTML-to-servlet communication the browser window automatically forms request URL and automatically forms query string having form data, when submit button is clicked. In applet-to-servlet communication all these activities should be taken care of by the programmers manually or explicitly as event handling operation.

Example on Application of Applet to Servlet Communication

Applet to Servlet Communication

Frame is a logical partition of the web page. Frame with name is called Named ,

Frame.

Step 1: Prepare the deployment directory structure of web application.

Request url http://localhost:2020/ AtoSApp/Main.html

Step 2: Develop the source code of above servlet program or web Application.

Source Code
 
MyApplet.java

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import Java.util.*;
public class wishsrv extends HttpServlet {
public void service(HttpServletRequest req,HttpServletResponse res) 
 throws ServletException , IOException {
  //general settings
  PrintWriter.pw=res.getWriter{);
  setContentType("text/html") ;
  //read form data
  String name=req.getParameter("uname") i
  //generate wish message
  Calendar cl=Calendar.getlnstance();
  int h=cl.get(Calendar.HOUR_OF_DAY);
  if (h<=12)
   pw. println ("Good Morning :"+name) i
  elseif(h<=16}
   pw.println("Good Afternoon: "+name);
  elseif(h<=20}
   pw.println("Good Evening :"+name);
  else
   pw.println("Good Night :"+name);
  //close stream obj
   pw.close();
 }//doGet
} / /class
<> javac MyServlet.java

web.xml
Configure MyServletprogram with /testurl url pattern and also configure Main.html as welcome file.

<web-app>
 <servlet>
   <servlet-name>abc</servlet-name>
   <servlet-class>MyServlet</servlet-class>
 </servlet>
 <servlet-mapping>
   <servlet-name>abc</servlet-name>
   <url-pattern>/testurl</url-pattren>
 </servlet-mapping>
 <welcome-file-list>
   <welcome-file>Main.html</welcome-file>
 </welcome-file-list>
</web-app>

Main.html

<frameset rows = "40% , *">
  <frame name = "f1" SYC = "Form.html">
  <frame = &nbsp;"f2" />
</frameset>

 
MyApplet.java

// MyApplet. Java 
import java.awt.*; 
import java.applet.*; 
import java.awt.event.*; 
import java.net.*; 
public class MyApplet extends Applet implements ActionListener  { 
  Button b; 
  TextField tfl; 
  Label l1; 
  public void init ()  { 
   l1 = new Label ("User name :"); 
   add(l1) ; 
   tfl = new TextField(10); 
   add(tf1) ; 
   b=new Button("Send"); 
   b.addActionListener(this) ; 
   add(b) ; 
 } 
public void actionPerformed(ActionEvent ae)  { 
  try{ 
   //read text value 
   String name=tfl.getText().replace(); 
   //frame query String 
   String qrystr=(“?uname=”+name) ; 
   //frame request url having query String 
   String url=(“https://ecomputernotes.com:2020/AtoSApp/testurl”+qrystr); 
   //create URL class object 
   URL requrl = new URL (ur1); 
   //getAppletContext obj 
   AppletContext apc=getAppletContext(); 
 } catch(Exception ee) 
 {} 
 {}

Form.html

<applet code= "MyApplet.class" width= "500" height= "500">
 </applet>

Step 3: Compile the source files of all servlet programs.

Step 4: Configure all the four servlet programs in web.xml file having four different url patterns.

Step 5: Start the server (Tomcat).

Step 6: Deploy the web application.

  Copy AutoSApp folder Tomcat_home \ webapps folder.

Step 7: Test the web application.

Open browser window type this url-https://ecomputernotes.com:2020/ AtoSApp/ Main.html

You’ll also like:

  1. Html to Servlet Communication
  2. Servlet to Database Communication
  3. Jsp To Servlet Communication
  4. Servlet to JSP Communication
  5. Java Applet – How to Shapes Drawn in applet.
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

Servlet Tutorials

Servlet Tutorials

  • Servlet - Home
  • Servlet - Types
  • Servlet - Advantages
  • Servlet - Container
  • Servlet - API
  • Servlet - Chaining
  • Servlet - Life Cycle
  • Servlet - Developement Way
  • Servlet - Servlet Vs CGI
  • Servlet - Server Side
  • Servlet - HttpServletRequest
  • Servlet - Cookies Advantages
  • Servlet - JDBC Architecture
  • Servlet - HttpServlet
  • Servlet - HttpServletResponse
  • Servlet - Web Technology
  • Servlet - Applet Communication
  • Servlet - Html Communication
  • Servlet - HTTP POST Request
  • Servlet - HTTP GET Request

Other Links

  • Servlet - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW