Chapter 7. Web Development Using Eclipse WTP

In this chapter, we are going to take a break from using Eclipse to develop applications for the client side. Instead, we are going to explore how Eclipse can be used to develop web-based Java applications. In order to develop such applications, we are going to use Java servlets and JavaServer Pages (JSP). To run and deploy our example applications, we are going to use Apache Tomcat. Different from desktop applications that run in a standalone fashion, web applications run in a server. Thus, this chapter also details how to deploy Java servlets and JavaServer Pages on a server, namely, Apache Tomcat.

This chapter starts off with a brief introduction to the benefits of Java-based web technologies. Then, we present some background on servlets and JavaServer Pages. We also briefly describe the role that Apache Tomcat plays in implementing these technologies. If you are already familiar with these topics, just skim these first sections and skip to the next subject: installing Apache Tomcat. You will also learn how to integrate Tomcat into Eclipse IDE so that you do not need to leave your development environment to deploy and run your web applications.

We will cover the following in this chapter:

  • Introduction to the benefits of the Java-based web technologies
  • Servlets
  • JavaServer Pages
  • Installing Eclipse web tools
  • Developing and deploying your first servlet
  • Developing and deploying your first JavaServer Page

Brief introduction to the benefits of Java web application technologies

Over the years, a multitude of ways of writing server-side software has been explored. In the early days, the Common Gateway Interface (CGI) was the most widely used technology to develop web content. However, CGI has many shortcomings. Because of these drawbacks, several technologies have been proposed to replace CGI. Java-based technologies, in particular servlets and JavaServer Pages, rapidly became de facto standard in building web-based applications. Java's widespread adoption in the server side can be ascribed to several factors. First, Java is usually faster than scripting languages. This is especially true for long-running applications because nowadays mainstream Java virtual machine implementations can perform adaptive optimizations that yield substantial performance improvements. Second, older technologies, such as CGI, require the server to spawn a separate process to deal with each request, whereas servlets can be executed in a multithreaded fashion. Finally, Java bytecodes are platform neutral, which allows for applications to be ported to different platforms without significant changes.

A number of enhancements to CGI have been proposed, such as FastCGI, mod_perl from Apache, and NSAPI from Netscape. These technologies solve the performance issue that hindered CGI from becoming even more widespread adopted. However, all of these alternatives to CGI share the same problem: HTML code is embedded directly into programming language code. Thus, the developer writing web applications in these technologies needs to have a mixed skill set: programming language skills for writing the business logic and web-related HTML skills for presentation. This is not desirable for a number of reasons. While servlets suffer from the same problem, JavaServer Pages overcomes this problem by making it possible to separate business logic and presentation properly, as we describe in our quick overview in the following sections.

Tip

You might be wondering what is HTTP and what does HTTP stand for. HTTP is a network protocol, it can be seen as the mean through which clients and servers communicate. The conversation between these two elements usually takes the following sequence: a client (browser) sends an HTTP request, which is answered with an HTTP response by the server. Usually, this response is an HTML (HyperText Markup Language) page, which is sent using HTTP. HTML tells the client how to show the server's response: the client reads through the message, renders it into a web page and shows it in the user's display. HTTP stands for HyperText Transfer Protocol.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset