You can call a servlet deployed to the Application Server by using a URL in a browser or embedded as a link in an HTML or JSP file. The format of a servlet invocation URL is as follows:
http://server:port/context-root/servlet-mapping?name=value
The following table describes each URL section.
Table 5–1 URL Fields for Servlets Within an Application
URL element |
Description |
---|---|
server:port |
The IP address (or host name) and optional port number. To access the default web module for a virtual server, specify only this URL section. You do not need to specify the context-root or servlet-name unless you also wish to specify name-value parameters. |
context-root |
For an application, the context root is defined in the context-root element of the application.xml or sun-application.xml file. For an individually deployed web module, the context root is specified during deployment. For both applications and individually deployed web modules, the default context root is the name of the WAR file minus the .war suffix. |
servlet-mapping |
The servlet-mapping as configured in the web.xml file. You can use the servlet-name instead if you enable the InvokerServlet; see Using the default-web.xml File. |
?name=value... |
Optional request parameters. |
In this example, localhost is the host name, MortPages is the context root, and calcMortgage is the servlet mapping:
http://localhost:8080/MortPages/calcMortgage?rate=8.0&per=360&bal=180000
When invoking a servlet from within a JSP file, you can use a relative path. For example:
<jsp:forward page="TestServlet"/> <jsp:include page="TestServlet"/>