Servlet wizard

This is a feature of JBuilder Professional and Enterprise.

To open the Servlet wizard, choose File|New, select the New tab of the object gallery, then double-click the Servlet icon.

The Servlet wizard creates a servlet consisting of two files and adds them to the existing project. (If no project is open, JBuilder runs the Project wizard first before it runs the Servlet wizard.)

Servlets are discussed in more detail, including the steps to create and launch a servlet, in "Developing servlets", or point your browser to the Java Servlet Reference Guide, with links to sites of interest in the servlet world, at http://webreview.com/97/10/10/feature/guide.html.

The Servlet wizard can create the following files:

The Servlet wizard consists of three pages:


Step 1 of 3

Servlet Details

The wizard displays default names for the Package and Class file. Enter the details for the servlet on this page.

Package

Displays the package name derived from the project file. To assign a different package name to the servlet file, click in the Package field and type in a new name.

For more information on packages, see the "Packages" topic in the "Creating and managing projects" chapter of Building Applications with JBuilder.

Class

Displays the default name assigned to the servlet class. To rename it, click in the Class field and type in a new name.

Get Content Type

The options for Generate Content Type include:

Generate Header Comments

Uses information from the project file as header comments at the top of the applet class file. This is the information entered in the Project wizard when creating the project file.
//Title:        Your Product Name
//Version:    
//Copyright:    Copyright (c) 1997
//Author:       Your Name
//Company:      Your Company
//Description:  Your description

Single Thread Model

If checked, a "tagging" interface that instructs the web server to guarantee that only one invocation of the servlet may be active at one time is implemented.

Implement Methods

Options for overriding the standard servlet methods. HttpServlet provides an abstract class that you can subclass to create an HTTP servlet, which receives requests from and sends responses to a web site. When you subclass HttpServlet, you must override at least one method, usually one of these. The methods generated are:


Step 2 of 3

The second step of the Servlet wizard is the SHTML file details page if you selected either HTML or XHTML from the Generate Content Type option. With JBuilder and the Tomcat servlet engine, you can run a servlet directly from the Servlet1.java file. When the servlet is created using the Servlet wizard, the Java properties option to Enable Web Run/Debug From Context Menu is turned off (to see this, right-click on the Java file, and select Properties from the context menu). If you want to run the servlet directly, as described in "Invoking a servlet from a browser window," unselect the Generate SHTML File option here.

If you want to call the servlet from an HTML page, as described in "Calling servlets from an HTML page," leave this option selected. An SHTML file with the same name as the servlet is added to the project when this option is selected.

SHTML File Options

If all options are selected, an SHTML file is created, and a <SERVLET> tag and an <A HREF> tag are added to the SHTML file. An example of the type of file that will be created is:
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<TITLE>
Servlet1
</TITLE>
</HEAD>
<BODY>

 launches servlet  Servlet1<BR>
<SERVLET
  CODEBASE=""
  CODE="untitled1.Servlet1.class">
</SERVLET>
<BR><a href="/servlet/untitled1.Servlet1">Click here
	to call Servlet: Servlet1</a><BR>
</BODY>
</HTML>

Generate SHTML File

Creates an SHTML file in the project.

Generate <SERVLET> Tag

If selected, a <SERVLET> tag is added to the SHTML file. The mechanism you use to link the controls to CORBA objects is the <SERVLET> tag.

Generate Link

If selected, an <A HREF> tag is added to the SHTML file. This creates a link to the servlet.

Background Color

The color of the background of the SHTML file as it appears in the browser.


Step 3 of 3

This page allows you to enter servlet parameters. Note that if HTML or XHTML are the selected content types, this is Step 3. However, if you select WML or XML, this is Step 2.

Enter Servlet Parameters

The grid on this page is used to enter the information that defines the parameters for your servlet. This information will generate PARAM tags within the FORM tag of the new HTML file, and parameter-handling code in the new Servletx.java file. Fields marked with an asterisk (*) are required fields.

The tutorial "Creating a servlet using the Servlet wizard" in Distributed Application Developer's Guide provides an example of how to incorporate parameters into your servlet.

Fill in one row of the grid for each parameter you wish to have.

Name

A name for the parameter. This will be used to provide the NAME attribute in the FORM tag in the HTML file, and to provide the name parameter of the corresponding getParameter() call in the Java source.

Type

A drop-down choice list from which you select the type of variable that will be inserted into the Java source code of your servlet for holding the value of the parameter coming in from the HTML page.

Desc

A brief description of the parameter. This will be used to generate comments and to label the form field in the generated HTML file.

Variable

The name of the variable that will be inserted into the Java source code of your servlet for holding the value of the parameter coming in from the HTML page.

Default

The default value for the parameter. This is the value that the Java source code in this servlet will use if some future HTML file that uses this servlet has no PARAM tag for this parameter. For an HTML file to provide this parameter, the NAME attribute in the PARAM tag must exactly match what you've entered in the Name column in this row of the grid. Note that this matching is case sensitive.