Use the Servlet section of the web.xml Visual Editor to add, remove, and view the deployment information of your web application's servlets and, optionally, JSP files.
Servlets are Java classes that can be loaded dynamically into a server and executed by the server to extend its feature set. Servlets are useful for tasks that involve processing an HTTP request. Servlets are also helpful for tasks that do not generate an HTTP response at all or that generate a relatively simple HTTP response. Servlets use the javax.servlet API.
To deploy a servlet, you must register it in the web.xml file. Doing this provides information needed by the server to deploy the servlet. For example, you tell the server which class should be loaded to deploy the servlet.
JSP technology was designed to simplify the process of creating servlets. In fact, the main function of servlets is to generate HTML output in cases where dynamic portions can be encapsulated. Servlets are generated by JSP pages when compiled. In many applications, the response sent to the client is a combination of template data and dynamically-generated data. In this situation, it is often easier to work with JSP pages than to do everything with servlets.
Unlike servlets, the server automatically deploys JSP files, therefore you do not have to register a JSP files in the web.xml file in order to deploy it. However, if you register a JSP file in the web.xml file, you can use servlet elements to set initialization parameters and mappings for the JSP file, just as if it were a servlet.
Before registering a servlet or JSP file in the web.xml file, you can create the servlet or create the JSP file in the New File wizard, or import it from your existing sources. You can use the Configure Servlet Deployment panel of the New File wizard to register a servlet. If you have not done so, or if you want to modify a registered servlet's deployment information, use the Servlets view of the web.xml Visual Editor. Note that you cannot use the New File wizard to register JSP files.
You open the web.xml Visual Editor from the Projects window by expanding the Web Pages node, then the WEB-INF node, and then double-clicking the web.xml file. Click Servlets at the top of the editor to open the Servlets view.
First, click Add Servlet Element to define the servlet element with the following properties:
When you click OK, the values you entered are displayed in the Servlets section. Optionally, you can now specify the startup order of the servlets in the application. In the Startup Order edit box, type an integer indicating the order in which the servlets should be loaded.
Initialization Parameters
Next, click Add within the servlet element and define its initialization parameters:
Security Role References
Optionally, click Add under Security Role References for the servlet to add role references:
Note that when you click Remove at the top of the Servlets section, you remove the definitions for the servlet or JSP file from the web.xml file, but you do not remove the servlet or JSP file itself. To delete the servlet or JSP file, right-click it in the Projects window and choose Delete.