Article

Home » Server-side Coding » Java and J2EE » Java Servlets - Part 1

About the Author

Kevin Yank

author_kev1 Kevin began developing for the Web in 1995 and is a highly respected technical author. He wrote Build your own Database Driven Website using PHP and MySQL, a practical step-by-step guide published by SitePoint, and he's co-author of the SitePoint Tech Times, a bi-weekly newsletter for technically-minded web developers. Kev believes that any good webmaster should have seen at least one episode of MacGyver.

View all articles by Kevin Yank...

Java Servlets - Part 1

By Kevin Yank

August 4th, 2001

Reader Rating: 9

Page: 1 2 3 4 5 6 Next

Whether you consider yourself to be an experienced Java developer or not, it's a safe bet that you've heard of Java Applets. Applets are little Java programs that run as part of a Web page. Since they're sort of 'mini-applications', they were dubbed 'applets'. Java Servlets got their name in a similar way.

Think of Servlets as highly efficient CGI programs written in Java. When a Servlet-capable Web server receives a request for a URL that corresponds to a Java Servlet, the server hands the request off to the Servlet for processing. The Servlet dynamically produces a response to the request (typically an HTML Web page) and sends it back to the requesting browser. If you think of Servlets in this context as 'mini-servers', their name makes perfect sense.

In this article, I'll take you through the basics of writing and deploying Java Servlets on your own Web server. I'll begin with the assumption that you're already equipped with a Servlet-capable Web server. While there are many offerings in this arena, the free combination of Apache and Tomcat is the most readily available. Most experienced Java developers prefer one of the slick, commercial solutions such as Caucho Resin, IBM WebSphere, or Allaire JRun (see a complete list); and while most of these are free for non-commercial use, the standard, "nitty gritty" methods supported by Tomcat are what we'll work with in this article. If you haven't already set up Apache and Tomcat, now would be a good time. See my JSP Quick-Start Guide for a helpful walkthrough, upon which the assumed configuration in this article is based.

By their very nature as Java programs, Servlets require a significant amount of knowledge to develop with. At the very least, you'll need to be familiar with the basics of the Java language before you undertake the task of writing your first Java Servlet. The previous articles in this series, Getting Started with Java, Java Language Basics and Object Oriented Concepts in Java Part 1 and Part 2 are definitely required reading if you're just making your start in Java programming.

If you're relatively comfortable with the features of the Java language presented in those articles, and you've got Apache and Tomcat running together on your server, you're ready to go! Let's write a Servlet!

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links