[ Team LiB ] Previous Section Next Section

Deploying a Servlet

Deploying servlets involves a few more steps than do HTML and JSP pages. Servlets must be defined in the Web application deployment descriptor, web.xml, and their deployment structures must match their package structures. The following steps will walk you through the deployment of a servlet:

  1. Create a directory to hold your servlet classes, if one isn't already present. Go to the Web application directory /DefaultWebApp, and under the /WEB-INF directory, create a subdirectory named /classes. If you created the domain mydomain from the first section in this appendix, your directory structure should resemble the following:

    
    
    C:/bea/user_projects/mydomain/applications/DefaultWebApp/WEB-INF/classes
    
  2. Copy your compiled servlet into the /classes subdirectory. If your servlet has a package statement, you'll need to create an additional subdirectory for each level of the package statement. For example, suppose that you have a servlet named BlackboardServlet, and it has a package statement of com.pirates. Your servlet class would be placed in the following location:

    
    
    
    C:/bea/user_projects/mydomain/applications/DefaultWebApp/WEB-INF/classes/com/pirates
    graphics/ccc.gif/BlackboardServlet.class
    
  3. Before we can start our servlet, we must register it. This is done in the Web application configuration file web.xml, which is stored in the /WEB-INF directory. That one file holds the registration information for all of your servlets. Check your /WEB-INF directory to see whether the web.xml file already exists. If so, bring it up in a text editor (or, preferably, an XML editor). If the file doesn't exist, open a text editor, create a new file, and save it as web.xml into the /WEB-INF directory.

  4. Edit the web.xml file with the servlet's information between the <web-app> and </web-app> tags. You can do this using any text or XML editor, or use the WebLogic Builder utility that comes with WebLogic. The format is as follows:

    
    
    <servlet>
     <servlet-name>
      BlackboardServlet
     </servlet-name>
     <servlet-class>
      com.pirates.BlackboardServlet
     </servlet-class>
    </servlet>
    
    <servlet-mapping>
     <servlet-name>
      BlackboardServlet
     </servlet-name>
     <url-pattern>
      TeachServlet
     </url-pattern>
    </servlet-mapping>
    

    where

    BlackboardServlet is the name of your Servlet class file.

    com.pirates.BlackboardServlet is the full package name of your servlet class.

    TeachServlet is the name that you type into the browser to access the BlackboardServlet. (This could also be the same name as the servlet or any other string.)

  5. Save the web.xml file into the /WEB-XML directory.

  6. Start the administration server.

  7. Call your servlet from a Web browser with the following URL:

    http://127.0.0.1:7001/DefaultWebApp/TeachServlet

    where

    localhost is the name of the WebLogic Server hosting the HTML page. If you deployed the HTML page on a remote machine, you would substitute the IP address or machine name of the other server for this name.

    port is the listening address for the server.

    TeachServlet is the reference to the servlet BlackboardServlet, defined between the <url-pattern> and </url-pattern> tags of the web.xml file.

    [ Team LiB ] Previous Section Next Section