The JSP/Servlet development environment

JavaServer Pages (JSP), a server-side scripting technology, enables you to embed Java code within static Web pages (HTML documents) and execute the Java code when the page is served. By separating presentation logic (content presentation) from business logic (content generation), JSP technology makes it easy for both the Java programmer and the Web page designer to create HTML pages with dynamic content.

In this section, you will learn about:

Overview

A Java servlet is a Java program that plugs into a Web server. A Web server can be extended to host servlets through a servlet engine. Servlets are highly extensible and flexible, making it easy to expand from client/single-server applications to multi-tier applications. Servlets enable businesses to connect databases to the Web.

You can develop, debug, and deploy servlets within the VisualAge for Java IDE. In the IDE, you can set breakpoints within servlet objects, and step through code to make changes that are dynamically folded into the running servlet on a running server, without having to restart each time.

For JSP-generated servlet code to be imported into the VisualAge for Java IDE, the following occurs:

  1. The JSP source is fed to a page compiler, which creates an executable object (for example, a Java HTTP servlet).
  2. VisualAge for Java then imports the generated servlet code. You can run and debug the servlet by using your browser to call the JSP that created the servlet. For example, for the SimpleJSP sample described below, you would refresh the following: http://127.0.0.1:8080/JSP/SimpleJSP/SimpleJSP.jsp

The scripted HTML file has a .jsp extension, in order for it to be identified by the server as a JavaServer Pages file. Before the JSP page is served, the JSP syntax is parsed and processed into an object on the server side. The resulting object generates dynamic HTML content and sends it back to the client.

A JSP file can be directly requested as a URL, called by a servlet, or called from within an HTML page. In all three cases, the servlet engine compiles the JSP into a servlet and runs it. The compilation is performed the first time the JSP is requested and each time the JSP source changes. Being able to compile on demand means that you can deploy new versions of JSP files into a running Web application. As well, performance is improved because you do not have to compile, load, and run a servlet each time a request is made to the server.
System concept for use of JSP technology

One way to easily create JSP files is by using WebSphere Site Developer Studio tools. WebSphere Application Server is IBM's Java servlet-based Web application server that helps you deploy and manage Web applications. WebSphere Application Server is a Web server plug-in based on a server-side Java programming model that uses servlets, JSP technology, and Enterprise JavaBeans (EJB) components.

Tools provided with VisualAge for Java

VisualAge for Java provides the following tools to ease JSP development:

Working with a sample that implements JSP technology

When installing VisualAge for Java, you will be prompted to indicate the document root on your system (the document root is where your Web resources, including HTML files and JSP files, are stored). Because there is minimal error-checking, make sure that the document root directory exists and is valid.

Note: If you want to change the document root later, you can change it in the doc.properties file. This file is located in the following subdirectory: \ide\project_resources\IBM WebSphere Test Environment\properties\server\servlet\httpservice\

To work with JSP in VisualAge for Java, you must first load the necessary features from the repository into the VisualAge for Java workspace. To perform a feature install, select File > Quick Start > Features > Add Features.

Select IBM JSP Execution Monitor. This automatically installs the following features:

Click OK to load the features into the workspace.

Note: The IBM JSP Execution Monitor contains the IBM JSP Examples. The IBM WebSphere Test Environment feature contains the WebSphere integration components.

You can now begin to work with the Simple JSP sample.

Use the Simple JSP sample to familiarize yourself with JavaServer Pages technology and the JSP Execution Monitor. This sample contains a simple JSP script that performs some basic functions. To access the samples index page (titled IBM WebSphere JSP Execution Monitor Samples) already installed on your hard drive, do the following:

  1. Start your Web browser.
  2. Launch the VisualAge for Java IDE.
  3. Launch the WebSphere Application Server. To do this, run the SERunner class by right-clicking on the SERunner class (located in your Project workspace under IBM WebSphere Test Environment > com.ibm.servlet), and then selecting Run > Run main. You will know that the server is successfully launched when you see ServerProcess: Server started in the Console window.

    Note: Please wait another 5 to 10 seconds to ensure that the server has started.

    If you get a run-time error, terminate the program by simply clicking Stop and Exit in the WebSphere Test Environment window, and then launch the WebSphere Application Server again.

    As soon as you have the WebSphere Application Server running in VisualAge for Java, you can serve JSP files and HTML files from the designated document root.

  4. Load the JSP Samples index page in your Web browser, by entering the following URL: http://localhost:8080/JSP/index.htm

    This page contains links to four JSP samples, including the Simple JSP sample.

  5. To step through the JSP source, you must enable the JSP Execution Monitor (by default, the JSP Execution Monitor mode is disabled):
  6. When you have enabled the JSP Execution Monitor, go back to the JSP Samples index page and click Simple JSP Example to access the sample.

Another detailed example implementing JSP is provided in the online help. The Developers Domain Registration sample demonstrates how to use JSP to get and set data.