The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: Servlets
Lesson: Calling Servlets

Calling Servlets From a Browser

The URL for a servlet has the following general forms depending on which server you are using. Context-root corresponds to the subdirectory of TOMCAT_HOME/webapps where you have installed your application. Servlet-name corresponds to the name you have given your servlet:
 

    (Tomcat) http://machine-name:port/Context-root/Servlet-name
    (JSDK) http://machine-name:port/servlet/Servlet-name

For example, to see the main page of the bookstore example, type the following URL into your browser:
 

    (Tomcat) http://localhost:8080/bookstore/enter
    (JSDK) http://localhost:8080/servlet/bookstore

Servlet URLs can contain queries, such as for HTTP GET requests. For example, the servlet that delivers details about a particuar book takes the stock-number of the book as a query. The servlet's name is bookdetails; the URL for the servlet to GET and display all the information about the bookstore's featured book is:
 

    (Tomcat) http://localhost:8080/bookstore/bookdetails?bookId=203
    (JSDK) http://localhost:8080/servlet/bookdetails?bookId=203

Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form