Updates
  • Starting New Weekday Batch for Full Stack Java Development on 27 September 2025 @ 03:00 PM to 06:00 PM
  • Starting New Weekday Batch for MERN Stack Development on 29 September 2025 @ 04:00 PM to 06:00 PM

Setup Tomcat 6

1. Make sure that JDK 6 is installed.
2. Install Tomcat 6 with the following steps:

• Click on the installer called "apache-tomcat-6.0.37," which is on the student DVD under the Tomcat 6.0 folder.
• Click on the next button.
• Click on the I agree button.
• Select the installation type as "full.
• Click on the next button.
• Provide the installation location as E:Tomcat 6.0 and click on the Next button.
• Provide

o Port number: 9999
o Username: som
o Password: som

• Click on the next button.
• Make sure that JRE 6 is selected, and click on the install button.
• Uncheck the two check boxes and click on the finish button.

3. Observe the Tomcat 6 directory structure:
Diagram

4. Start the server with the following steps:

• Start->Programs->Apache Tomcat 6.0->Configure Tomcat.
• Modify the startup type to manual and click on “Apply”.
• Click on the START button.

5. Check the Tomcat status.

• Open the browser.
• Type in the following URL: http://localhost:9999/

6. Stop the server with the following steps:

• Start->Programs->Apache Tomcat 6.0->Configure Tomcat.
• Click on the next button.

Steps to develop and run your first Servlets 2.x-based web app.

1. Consider the login requirement.
Diagram……

2. Create the dynamic web project in Eclipse as follows:

• Select File->New->Dynamic Web Project.
• Provide

o Project Name: Jtc1
o Click on the New Runtime button (for the first time).

■ Select Apache Tomcat 6.0 and click on the Next button.
■ Browse the Tomcat Home Directory, i.e., E:\Tomcat 6.0.
■ Click on the finish button.

• Click on the finish button.

3. Observe the following directory structure of the Dynamic Web Project in Eclipse:
Diagram………
4. Create login.html under the WebContent folder.
5. Create a package called com.jtcindia.servlets.
6. Create the LoginServlet.java file in package com.jtcindia.servlets.
7. Update the web.xml with the LoginServlet configuration.
8. Deploy into Tomcat 6 as follows:

a. Right-click on Jtc1.
b. Select Run As->Run on Server.

9. Open the Browser.
10. Provide the following URL: http://localhost:9999/jtc1/login.html

Required Files for Jtc1 Program

1. Login.html
2. web.xml
3. JtcServlet.java

1. Login.html

            
<html>
  <head>
    <title>Insert title here</title>
  </head>
  <body>
    <h1>JTC Test</h1>
    <hr>
    <br>
    <form action="test.jtc" method="post">
      <table>
        <tr>
          <td>UserName</td>
          <td>
            <input type="text" name="uname" />
          </td>
        </tr>
        <tr>
          <td colspan="2" align="center">
            <input type="submit" value="Submit" />
          </td>
        </tr>
      </table>
    </form>
  </body>
</html>
        
            

2. web.xml

            
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
  <welcome-file-list>
    <welcome-file>login.html</welcome-file>
  </welcome-file-list>
  <context-param>
    <param-name>State</param-name>
    <param-value>UTTAR PRADESH</param-value>
  </context-param>
  <context-param>
    <param-name>country</param-name>
    <param-value>INDIA</param-value>
  </context-param>
  <servlet>
    <servlet-name>test</servlet-name>
    <servlet-class>com.jtcindia.Servlets.JtcServlet</servlet-class>
    <init-param>
      <param-name>Email</param-name>
      <param-value>som@jtcindia.org</param-value>
    </init-param>
    <init-param>
      <param-name>Phone</param-name>
      <param-value>33333</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>test</servlet-name>
    <url-pattern>/test.jtc</url-pattern>
  </servlet-mapping>
</web-app>
        
            

3. JtcServlet.java

            
package com.jtcindia.Servlets;
import.IOException;
import.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
public class JtcServlet extends HttpServlet {
   /*
    * @Author : Som Prakash Rai
    * @Join : JTC
    * @visit : www.jtcindia.org
    *@Call :+91-9990399111
    * */
   String phone;
   String email;
   String state;
   String country;
   public void init(ServletConfig sc) {
      System.out.println("TestServlet -init()");
      // 1.config parameter
      phone = sc.getInitParameter("Phone");
      email = sc.getInitParameter("Email");
      // 2.context parameter
      ServletContext ctx = sc.getServletContext();
      state = ctx.getInitParameter("State");
      country = ctx.getInitParameter("country");
   }
   public void service(HttpServletRequest req,
      HttpServletResponse res)
   throws IOException, ServletException {
      System.out.println(("TestServlet-service()"));
      // 3.Request parameter
      String un = req.getParameter("uname");
      // 4.display parameters
      PrintWriter out = res.getWriter();
      out.println("<h1>Username: " + un + "</h1>");
      out.println("<h1>Phone: " + phone + "</h1>");
      out.println("<h1>Email: " + email + "</h1>");
      out.println("<h1>state: " + state + "</h1>");
      out.println("<h1>Country: " + country + "</h1>");
   }
   public void destroy() {
      System.out.println("TestServlet-destroy()");
   }
}