Creating a Servlet Source File

See Also

Servlet source files are created and managed in the IDE in much the same way as other file types. The easiest way to work with servlet source files from the IDE is to put them in a subdirectory of WEB-INF/classes of a mounted web module. When you create the servlet using the following steps, the IDE puts the class and its package structure under WEB-INF/classes.

To create a servlet source file:

  1. In the Filesystems window, right-click the web module's WEB-INF node and choose New and choose All Templates from the contextual menu. A New wizard appears.
  2. In the New Wizard, expand JSP & Servlet, select Servlet, and click Next.
  3. In the General Servlet Information page, specify the location and fully qualified class name. Do not include a filename extension as this is added automatically when the file is created.
  4. (Optional) Click Next to specify the server deployment configuration for the servlet. This page does not enable the Finish button until you enter a servlet name that is unique to the deployment descriptor. After you create the servlet, you can edit this information in the deployment descriptor (web.xml).
  5. Click Finish. The IDE opens the file for editing in the Source Editor.
tip  If you want to keep your source separate from your class files, you must mount the directory above the package root and you must use the Options window to select WEB-INF/classes as the project's target directory for the External Compiler. Doing so ensures that code completion and compiling are supported by the IDE.

If you create a servlet outside the IDE, the IDE treats the servlet as an ordinary Java class. For the servlet features to be available, you must tell the IDE to treat this class as a servlet. Right-click the class and choose Tools and choose Mark as Servlet from the contextual menu. When the class is marked as a servlet, the class's property window has properties for the URI, request parameters, and content language.

For information on other file management tasks, such as mounting and unmounting filesystems, creating and customizing templates, and searching for files, see "Managing Objects in the IDE" in the Core IDE Help Set.

See also
Editing a Servlet Source File
Servlet Property Sheet
About Running Web Modules
About Debugging Web Modules
About Creating Web Modules
Where to Put Web Module Files

Legal Notices