JSP Servlets   «Prev  Next»

Lesson 1
Java Servlets

Servlets interact with Applets

In this module I will discuss how an applet can communicate with a servlet. When you send information from a form to a servlet, the flow is one-way: the form sends information to the servlet, and in return the servlet sends information to the browser, which replaces the form displayed. With an applet involved, two-way communication is much simpler. After completing this module you will be able to:
  1. Design an applet that will communicate with a servlet
  2. Add code to an applet to send a GET request to a servlet
  3. Add code to an applet to read the servlet response
  4. Write a servlet that responds to an applet

Applet Servlet Communication

This module demonstrates several techniques by which applets can communicate with servlets. We are going to come at the topic from a slightly different angle than you might expect. Instead of assuming you have an applet and a servlet that need to communicate, we are going assume you have an applet that needs to talk to some entity on the server and explore why sometimes that entity should be a servlet. Let us think about applets that need to communicate with the server. Take a look at the administration applet that manages the Java Web Server. Think about how it works, it executes on the client, but it configures the server. To do this, the applet and the server need to be in near constant communication. As another example, take a look at one of the popular chat applets. One client says something, and all the rest see it. How does that work?
They certainly do not communicate applet to applet. Instead, each applet posts its messages to a central server, and the server takes care of updating the other clients. Finally, imagine an applet that tracks the price of a set of stocks and offers continuous updates.

"Java Applet" to "Java Servlets" communication as an architecture been phased out

Yes, Java Applet to Java Servlet communication has largely been phased out. Java Applets, which were used to run Java code in web browsers, have been largely replaced by other technologies such as JavaScript, HTML5, and WebAssembly. This is due to several reasons, including:
  1. Security concerns: Java Applets had a history of security vulnerabilities, which led to browsers dropping support for them.
  2. Browser support: Modern web browsers have mostly discontinued support for Java Applets.
  3. Alternative technologies: Other technologies have emerged as more popular choices for web development.
Java Servlets, on the other hand, are still widely used as a server-side technology for building web applications. However, they are typically used in conjunction with modern web development frameworks and technologies, rather than with Java Applets. If you're looking to build a new web application, you may want to consider using more modern technologies such as 1) Spring Boot, 2) Node.js, or 3) Django, which offer more efficient and secure ways of building web applications.

SEMrush Software