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:
- An SHTML file containing a SERVLET tag referencing your Servlet class, if selected, as well as a link to call the Servlet, if this option is selected.. This is the file you should select to launch or debug your servlet. The SHTML file will not be generated if the Generate SHTML File option is unchecked.
- A Java class file that extends
httpServlet
. You customize this class to define what the servlet does when launched. Any parameters entered on the Parameters page of the Servlet wizard are defined in this file.
- A Java file that implements a simple server that can be used to test and debug the servlet.
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:
- HTML - HyperText Markup Language. A markup language for hypertext documents on the Internet. HTML enables the embedding of images, sounds, video streams, form fields, references to other objects with URLs, and basic text formatting.
- XHTML - a reformulation of HTML 4.0 as an application of XML. The tags and attributes are almost identical to HTML, but XHTML is a stricter, tidier version of HTML. For example, all XHTML tags are lowercase, and all open tags must have a closing tag. XHTML allows web designers to move toward a more modular and extensible web based on XML while maintaining compatibility with today's HTML 4 browsers.
- WML - Wireless Markup Language. WML files are regular text files containing XML content. Due to the restricted bandwidth and memory capacity of the mobile devices, such content has to be compiled into compact binary form before it can be presented on a Wireless Application Protocol (WAP)-enabled device. The JBuilder browser does not currently support WML, so you will need a WML-enabled browser to test your application.
- XML - eXtensible Markup Language. A markup language that allows you to define the tags (markup) needed to identify the data and text in XML documents. The JBuilder browser does not currently support XML, so you will need an XML-enabled browser to test your application.
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:
doGet()
- override this method if the servlet supports HTTP GET requests. The GET method allows a client to read information from the Web server, passing a query string appended to an URL to tell the server what information to return.
doPut()
- override this method if the servlet supports HTTP PUT requests. The PUT operation allows a client to place a file on the server and is similar to sending a file by FTP.
doPost()
- override this method if the servlet supports HTTP POST requests. The HTTP POST method allows the client to send data of unlimited length to the Web server once and is useful when posting information such as credit card numbers.
doDelete()
- override this method if the servlet supports HTTP DELETE requests. The DELETE operation allows a client to remove a document or Web page from the server.
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.
- To select a cell, click it or use the keyboard navigation arrows to move to it.
- To enter a value in a cell, type in a value, or select one if a drop-down list exists.
- To add a new parameter, click the Add Parameter button.
- To remove a parameter, click in any cell of the parameter row, then click the Remove Parameter button.
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.