Find out why and how people are using servlets -- 6+ key benefits (and a few concerns) detailed! Servlets have been getting a lot of press lately (including the two cover stories in this month’s JavaWorld). But how are developers really using servlets, and why are they employing servlets instead of some other technology? That’s the question in this month’s poll.The responses have been overwhelmingly positive toward servlets. JavaWorld readers use servlets for everything from simple file serving to acting as the brains of their Web application. And they choose servlets over alternative approaches for quite a variety of reasons.Let’s look at the results. The numbersMore than 600 JavaWorld readers responded to the poll question, “Why do you use servlets?” Here’s a look at the actual voter breakdown:38% said As a Web-based application21% said To replace CGI17% said To access a database13% said I don’t use servlets4% said To serve HTML pages3% said Other0% said To generate imagesWhoa! Is it true that only 4 percent of developers use servlets to generate HTML? Probably not. These numbers can be misleading, unless you keep in mind (as the page indicated) that readers could choose only one item from the list, even if they use servlets for several tasks. In the comments section, many readers indicated that they use servlets for multiple tasks.You needed an “All of the above” option. I use servlets to serve HTML, replace CGI, access databases, to create Web-based applications, and to generate images.Hey, I use them for more than one thing! To replace cgi, to serve pages, to access databases, as Web based-applications and other (I define servlets which handles other protocols than http, like POP3 and FTP). I use servlets on the client machine (in proxy servers). I think this is a very limited survey!Why do I have to choose only one of the uses for servlets? I use servlets to access databases and to serve html pages, and thereby they have completely replaced the use of CGI programs in my company. Why do I use servlets? The answer to this question is easy: It’s easy – if already know Java, writing a servlet is not difficult. All communications problems have already been taken care of, so you only have to worry about what the servlet should do, and not about how it should return it to the client. Because it is so easy to write a servlet, it is of course also a fast way of developing, which is excellent. tw e-mail: bex@forum.dkWell that’s a stupid survey. Making people click only one checkbox is ridiculous. I use servlets for all of those things (and more), and most people are going to want to generate HTML *and* replace CGI, and of course it’s a Web-based app for more folks. Come on, put a bit more work into writing this survey, at the moment it looks like a joke!Turns out the software (a CGI program) used for tabulating poll results limits voters to one item. Rumor has it a future version (built using servlets) won’t have this limitation. In the meantime, JavaWorld will redouble its efforts to ask questions that work better within the software’s limitations — and continue to encourage readers to use the comments section to detail their opinions (which, after all, usually offer information that’s more valuable than mere numbers or pie charts). The top tenHere are the top ten categories for why and how people use servlets (or why they don’t use servlets).For those who counted and found only nine: Send your resume to qa-jobs@kasoftware.comPlatform independence Perhaps the most popular reason given for using servlets is platform and server independence.Thanks to Java servlets I’m not tied to proprietary APIs.By programming with the servlet API, I am not tied to any particular development environment or technology. Plus, I don’t have to put up with “childish” technologies like ASP.We use servlets for a number of the options listed, serve HTML, CGI replacement, database access, etc. Our principal reason for using them is to serve our heterogeneous server platforms — Solaris, NT, Linux running a mixture of Apache, IIS, and various Netscape servers. Having a single API is an absolute MUST. Also servlets offer good performance returns and are MUCH simpler than using proprietary HTTP server APIs. John@swingsoft.comI have used Perl and it worked well, but it can be very cryptic and can be server-dependent. Java has the platform independence that allows me to move my application to any server without recompiling. After having build a significant system using Netscape WAI (I really liked having CORBA), I found that servlets were much better and I can still instantiate an ORB or RMI and do the things I need to do.We considered other technologies but servlets form the best choice since they provide a platform-independent way of serving up Web clients and also makes writing server-side code in a truly programmatic way as if we write other applications. I believe servlets have a lot of power … [They have] to only go beyond Microsoft’s Marketing Machine…(read ASP).Platform independence from proprietary APIs for accessing databases.Power Several readers cited power as the reason to use servlets. More control and OO than using ASP or CGI!!!!Servlets make me look like a Web Wizard!! The biggest benefit they have given me is the ability to make quick changes based upon customer needs — and doing it most of the time without taking the Web server down!Servlets open the whole Java platform for me to do stuff that I can never do with CGI etc….Servlets make it possible to develop fairly advanced distributed applications on a low budget (compared to CORBA or RMI). By streaming objects between server and clients, on top of HTTP, the potential is limited only by imagination. Applications will never lose their connections (because there aren’t any :-)) and client-side firewalls are automatically by-passed. Servlets are here to stay. Knut Martin Tornes, objectBOX (Norway)Performance Performance was another popular reason to use servlets.I use servlets for everything… I’ve replaced most of my old Perl CGIs with servlets. The performance alone is worth it, let alone the power and flexibility of Java.We use servlets to serve all our site’s pages — for display they are run through a templating servlet, and for form POST handling there are servlets that hit an Oracle database. Our site is mostly an application — lots of interaction, not a huge number of our own content pages (we link to travel-related content from all over instead). Servlets are a huge win in terms of being able to develop a fast, robust Web application.Ease of use Ease of use was another often cited reason. Servlets provide a simple API for constructing robust applications. They are easy to program and maintain.ISAPI DLLs are a pain to debugIt’s also better than using Perl. Cleaner, robust, OO, and much fun than using Perl. Easier to access database.When I started working as a webmaster/CGI developer I used Perl: effective but IMHO totally unreadable. Servlets came as a breath of fresh air: At last I could write my server-side progs in Java (the best OO language and API collection I’ve ever seen). I other words (pardon my French): servlets kick ass. Paul Pesz, Wroclaw, PolandDatabase access A large number of people report using servlets to access a database. Servlets and JDBC: a power combination to create manageable Web sites. I also use them to generate HTML pages containing the results of query and to process forms for adding new records in my database.Actually I would have checked all five buttons above. Servlets are the best way to implement the middle level of a three-tier architecture in the context of the Web. I use [servlets] to access a database (geographical), hence to generate images in a better way than using CGI, and the result is to serve HTML pages displaying images with dynamic aspects.To talk with applets Another popular use of servlets is to talk with applets. (One reader also mentioned using servlets to replace applets.)We do use servlets to generate HTML on the fly (when creating HTML forms, etc.), but recently we’ve used a servlet in a distributed computing scenario because we weren’t permitted to use RMI in the organization. Serialized objects are passed over HTTP from the server and back to our Java/Swing client. Therefore, the clients have no connections to databases (there are 4!) and we can install as many distributed Web servers as necessary around the world to boost performance. Great stuff!To build client/server applications (client = applet, server = servlet) For our product, servlets with JDBC solve the problem of slow download time and poor performance of Java applets.Code protection Another reader pointed out that using a servlet protected “sexy bits of code” from prying eyes.To protect some of my program content from being copied, i.e. the sexy bits of the code go in the servlet, the rest in the applet.A mix of reasons A number of readers use servlets in ways that defy easy categorization: We use servlets to: 1) replace inefficient CGI processes 2) permit persistent DB connections 3) permit system design to allow Web server to be scaled independently of the database server 4) the client request thread management can be delegated to Domino Go Web serverServlets are the foundation of our Web arch. We use them for everything from simple e-mail forms to large-scale database access applications.We let our customer personnel, users, and project members browse our bug report database with a servlet (a Microsoft Access file).Servlets are the most easy and powerful way to develop Web-based (both internet and intranet) applications that: (i) need to access a database, (ii) need to work from every computer without any installation, and (iii) work from very thin clients. Also, they are a great way to get rid of the usual CGIs. Lior SharonTraditional server-side applications and extensions written in Perl, C/C++, or other languages can be replaced using Servlets. By using Servlets as an extensible, well-defined, cross-platform environment, sophisticated applications for the server become easier to develop, faster to deploy, and more cost-effective to maintain.Don’t use servlets or are unhappy Finally, some readers either don’t use servlets or are unhappy with servlets. Here are their comments:The only reason I got into servlets was because CORBA didn’t want to work from a Java application started from a CGI Perl script. If not for that, I still wouldn’t be using servlets.I don’t know what servlets are…!!They seem like a good idea but I worry about the usual performance and reliability problems.Servlets simply do not provide enough interactivity. Either I simply use HTML pages or I use applets. Servlets are too wishy-washy.I’d rather build full blown Applet/Server combos using RMI — Business logic on the server; applet presentation; RMI to pass things back and forth.I don’t use them, but that’s just because my ISP (Demon Internet, in the UK), doesn’t support them. If they did, I would.I’m a big Java fan and have been since the beginning, but server-side Java is the dumbest application I’ve ever seen. Server-side is absolutely the domain of high-performance apps written in C. There’s no reason to slow down a server with Java!The Web Server we have here does not support servlets (yet).Keep an eye out for future JavaWorld polls and reports on results. –Jason Hunter Web DevelopmentJava