When should one use applets and when should one use servlets?

Alex Chaffee

Applets run inside browsers, and servlets run inside servers. So broadly speaking, use applets when you need dynamism on the client side, and use servlets when you need dynamism on the server side.

Servlets can produce any HTML (or indeed, any file type), and therefore are much more versatile than applets. Servlets can tailor the HTML they produce based on the browser type (as specified in the "User-Agent" header), and thus can produce output that will work in virtually any client, including WAP browsers or the like. Applets are notoriously poorly supported, and even in browsers that ostensibly have Java support, don't work consistently.

Servlets can also produce HTML with embedded JavaScript, which allows a fair amount of dynamic behavior on browsers which support it.

However, due to the infuriating limitations and bugs in JavaScript, sometimes you've just got to have an applet to get the client-side behavior you want. In these cases, take comfort in the fact that you can generate HTML containing APPLET tags from inside a servlet.
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact