• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Servlet » introduction » Creating and Executing Servlets
Next →
← Prev

Creating and Executing Servlets

By Dinesh Thakur

Servlets are platform independent and can work with almost all the web servers. They can be executed on any web server that supports the servlet API. Some of the web servers having built-in support for Java servlets are Tomcat server (Apache), Java web server (Sun Microsystems), Enterprise server (Netscape), Zeus web server (Zeus Technology), Tengah application server (Weblogic) and Sun web server (Sun Microsystems).

In this unit, we will be using the Tomcat server to explain the steps required to execute the servlet in Windows environment. Assume that the default location of Tomcat 6.0 is as follows.

C:\Program Files\Apache Software Foundation\Tomcat 6.0\

Following are the steps to create and execute the servlet.

1. Create a . java source file containing the code for creating servlet and save it with the name, say Sample. java.

2. Compile this source file, as a result Sample . class file will be created.

3. Copy the Sample. class file in the directory under the webapps directory of Tomcat. The

path for the directory is as follows.

C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\MyApp\WEB-INF\classes

Add the name and mapping of this servlet in the web . xml file. The path of this file is as follows.

C:\Program Files\Apache Software Foundation\Tomcat6.0\webapps\MyApp\WEB-INF

4. Add the following statements in the section which defines the servlets.

<servlet>

     <servlet-name>Sample</servlet-name>

    <servlet-class>Sample</servlet-class>

</servlet>

Also, add the following statements in the section which defines the servlets mappings.

<servlet-mapping>

     <servlet-name>Sample</servlet-name>

     <url-pattem>/servlet/Sample</url-pattem>

</servlet-mapping>

5. Start the Tomcat. To start the Tomcat, click the Start menu, point to All Programs, point to Apache Tomcat 6.0 and then click Configure Tomcat. This displays the Apache Tomcat Properties. Click the Start button.

6. Start a web browser and request for the servlet. Note that the HTML code can be included in the servlet code or a separate HTML file can be used. If the HTML code is included in the servlet code, enter the following URL in the address bar.

https://ecomputernotes.com:8080/MyApp/servlet/Sample

or

http:/1127.0.0.1:8080/MyApp/servlet/Sample

If separate HTML file is used for the HTML code, enter the following URL in the address bar.

https://ecomputernotes.com:8080/MyApp/Sample.html

or

http:/1127.0.0.1:8080/MyApp/Sample.html

Here, 127 . 0 . 0 . 1 : 8O80 is an IP address of the local system. Note that the . html file must be saved in the MyAppdirectory.

The output of the servlet will be displayed in the display area of browser.

You’ll also like:

  1. How to Generating and executing JAR files
  2. Types of Servlets
  3. Advantages of Servlets
  4. Servlets Client HTTP Request
  5. Additional Capabilities of HTTP Servlets
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

Servlet Tutorials

Servlet Tutorials

  • Servlet - Home
  • Servlet - Types
  • Servlet - Advantages
  • Servlet - Container
  • Servlet - API
  • Servlet - Chaining
  • Servlet - Life Cycle
  • Servlet - Developement Way
  • Servlet - Servlet Vs CGI
  • Servlet - Server Side
  • Servlet - HttpServletRequest
  • Servlet - Cookies Advantages
  • Servlet - JDBC Architecture
  • Servlet - HttpServlet
  • Servlet - HttpServletResponse
  • Servlet - Web Technology
  • Servlet - Applet Communication
  • Servlet - Html Communication
  • Servlet - HTTP POST Request
  • Servlet - HTTP GET Request

Other Links

  • Servlet - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW