Servlets Property Editor

Tip Note that this feature might not be included in your version of the IDE. If it is not available, you can edit the deployment descriptor (web.xml) file using the editor of your choice. For more information, see Java Servlet 2.3 Specification available at http://java.sun.com/products/servlet .

The Servlets property editor provides a way to designate deployment properties for servlet files in the web module. These properties are equivalent to those you specify in the JSP File property editor. However, in this case a servlet class is used for the named servlet implementation rather than a JSP file.

To display the Servlets property editor:

  1. Click the Deployment pane of the web.xml property sheet.
  2. Click the Servlets value field to make the ellipsis button (...) appear. Then click the Ellipsis button.

Alternatively, you can edit the deployment properties of a specific servlet in your web module:

  1. From the Explorer, select the desired servlet.
  2. From the servlet's contextual menu, choose Properties.
  3. Click the Deployment Entries field to edit servlet properties.

    To add servlet file deployment data: From the Servlets property editor, click the Add button.
    The Add Servlet dialog box appears.

    To edit servlet file deployment data: From the Servlets property editor, select the desired servlet, and click the Edit button.
    The Edit Servlet dialog box appears.

    To remove servlet file deployment data: From the Servlets property editor, click the desired servlet and the Remove button.
    The servlet is removed from the table. Click OK to confirm the action or Cancel to stop the action.

    Add Servlet and Edit Servlet dialog boxes: Contain text fields and checkboxes for deployment data, an initialization parameters table, and a security role references table.

    Deployment Data

    The following deployment data can be specified in the Add Servlet and Edit Servlet dialog boxes.

    To specify a servlet name: Type the desired name in the Servlet Name text field, for instance, FormProcessingServlet. This designation is often the same name as the servlet class. However, the servlet class could have an obscure name such as GenericSearchServlet when you want a more basic name in the web module, for instance, search.

    To specify a display name: Type the desired name in the Display Name text field. Like the small and large icons described below, the display name is not used within the IDE, but can be specified for use by other J2EE-compliant tools, such as a deployment tool for a particular web server.

    To provide a description: Type the desired information in the Description text field. This field can be used to provide additional information, such as what the servlet does. The Description field is optional, so you don't have to type anything here. Like the Display Name field, this data is not used by the IDE, but could be used by an external tool.

    To specify a servlet class: Enter the desired class in the Servlet Class text field. Click the Browse button to navigate to the desired servlet class using a file chooser. Use the qualified class of the servlet implementation, such as com.myCompany.myProject.GenericSearchServlet.

    To designate mappings:

  1. Click the ellipsis button in the Mappings text field to designate the desired mappings for the servlet. The Edit Servlet Mappings dialog box appears.
  2. Click Add. The Add Servlet Mapping dialog box appears.
  3. Type the desired servlet name in the Servlet Name text field.
  4. Type the associated URL pattern in the URL Pattern text field.
  5. Click OK in this dialog box, and then click OK in the Edit Servlet Mappings dialog box. The designated servlet mappings appear in the Mappings field of the Add Servlet dialog box.

To specify a small or large icon: Use this field to designate external tools such as a deployment tool that might represent the web module that could use these icons to represent the servlet. Developers can specify the icons to use here, but the icons are not actually displayed by the IDE. The information in this field corresponds to the <large-icon> and <small-icon> elements in the deployment descriptor.

  1. Click the ellipsis button next to the Small Icon (16x16) or Large Icon (32x32) text field. The Edit Icon dialog box appears.
  2. In the Image Source pane, you can designate a URL, file name, or class path to the icon by clicking the appropriate radio button. You can also indicate that no picture is to be provided by clicking the No picture radio button.
  3. Type the correct URL, file name, or class path in the Name text field, and click OK. The icon information appears in the Add Servlet dialog box.

To specify load on startup: Use this field to designate whether the servlet should load when the web container starts the application. By default, the servlet does not load upon startup. This information corresponds to optional <load-on-startup> element in deployment descriptor.

  1. Click the Load on Startup checkbox to indicate that the servlet should be loaded at the time the web container starts the application. The Order text field is now editable.
  2. To change the order in which the web container loads the named servlet at application startup, type the desired number in the Order text field. Named servlets are loaded starting from number 1.

Initialization Parameters

You can add, edit, or remove initialization parameters for the servlet. Each entry corresponds to an <init-param> element in the deployment descriptor.

To add an initialization parameter:

  1. Click the Add button in the Init Parameters pane. The Add Init Parameter dialog box appears.
  2. Type the name for the initialization parameter into the Init Param Name text field. The initialization parameter can be any value you want made available to the servlet, but that needs to be editable at deployment time so it can be changed when the servlet is deployed. Examples of initialization parameters would include a database driver name, URL, login, or password.
  3. Type in the value for the intialization parameter into the Init Param Value text field.
  4. Type in an optional description of the intialization parameter into the Description text field. The description provides guidance about the value that should be entered for the initialization parameter. It is optional and is not used by the IDE, but could be used by an external deployment tool.
  5. Click OK for the initialization parameter you have described to appear in the Add Servlet dialog box.

To edit an initialization parameter:

  1. Select the desired initialization parameter from the table, and click the Edit button in the Init Parameters pane. The Edit Init Parameter dialog box appears.
  2. Edit the information for the initialization parameter in the Init Param Name text field.
  3. Edit the value for the intialization parameter in the Init Param Value text field.
  4. Edit the description of the intialization parameter in the Description text field.
  5. Click OK for the initialization parameter you have edited to appear in the Edit Servlet dialog box.

To remove an initialization parameter:

  1. From the Add Servlet dialog box, click the desired initialization parameter and the Remove button. The initialization parameter is removed from the table.
  2. Click OK to confirm the action or Cancel to stop the action.

Security Role References

A security role reference must be declared when you have used programmatic security within the component, in this case, the servlet file. This information is used to determine which resources a user is permitted to access. Resources are defined by the web resource collection.

The security-role-ref element defines a mapping between the name of role called from a servlet using isUserInRole(String name) and the name of a security role defined for the web application.

To test programmatically whether the current user is in a given role, you can use the isUserInRole method on the HttpServletRequest object, passing the logical user role name as a parameter. Of course, developers, assemblers, or deployers might not assign the same logical name for a user role. For example, two programmers working on two different servlets might think of the same logical role of administrator, but use different names such as admin and administrator. Therefore, when the servlets are placed in the web module, each servlet declares a security role reference. The deployer can link each of these references to a role name in the deployed web module. Some examples might include admin, administrator, or a new term, such as sys-admin.

Each entry corresponds to a <security-role-ref> element in the deployment descriptor. Note that the <security-role-ref> refers to a programmatic reference in the JSP/servlet component, but is linked to a web-module-wide <security-role> through the <role-link> child of the <security-role-ref>. In other words, to map the programmatic reference to the web module's role, /web-app/servlet/security-role-ref/role-link == /web-app/security-role/role-name.

To add a security role reference to the servlet:

  1. Click the Add button in the Security Role References Pane. The Add Security Role Reference dialog box appears.
  2. Type the desired name for the security role reference in the Role Ref Name text field, followed by an optional description in the Description text field. A security role reference is simply a token value that identifies a class of users, for example, guest or member.
  3. Type the desired link to the security role in the Role Ref Link text field, and click OK. The information you have entered now appears in the Security Role Reference pane of the Add Servlet dialog box.

To edit a security role reference:

  1. Select the desired security role reference from the table, and click the Edit button in the Secutity Role Reference pane. The Edit Security Role Reference dialog box appears.
  2. Edit the information for the security role reference in the Role Ref Name text field.
  3. Edit the description of the security role reference in the Description text field.
  4. Edit the link for the security role reference in the Role Ref Link text field.
  5. Click OK for the security role reference you have edited to appear in the Add Servlet dialog box.

To remove a security role reference:

  1. From the Add Servlet dialog box, click the desired security role reference and the Remove button. The security role reference is removed from the table.
  2. Click OK to confirm the action or Cancel to stop the action.
See also
Editing Web Module Deployment Properties
Editing Web Module Security Properties

Legal Notices