save up to 40%

How to install and configure Tomcat for Windows(tm)

Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.

How to install and configure Tomcat for Windows(tm)

Rating:

To install and configure Tomcat, you will have to take the following steps:

  1. Download JDK 1.5 from Sun(tm) site at http://java.sun.com/javase/downloads/index_jdk5.jsp


  2. Install JDK to C:\Program Files\Java\jdk1.5.0_08



  3. Download Tomcat 5 from http://tomcat.apache.org/download-55.cgi


  4. Install Tomcat on C:\Program Files\Apache Software Foundation\Tomcat 5.0



  5. Set the port number to 8080, which is the default port. Set the name as admin and password as desired. The password column can even be left blank.



  6. Set the environment variables as follows:
    • Right-click My Computer and select properties.



    • Click the Advanced tab button.



    • Click Environment Variables.



    • Select New to set the properties as follows:

      1. Classpath: In the variable name field write classpath, and in the variable value field write the location of servlet-api.jar file as C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar




      2. Path: In the variable name field write PATH, and in the variable value field write the location of JDK installation as C:\Program Files\Java\jdk1.5.0_08\bin;.;




      3. CATALINA_HOME: In the variable name field write CATALINA_HOME, and in the variable value field write the location of Tomcat installation as C:\Program Files\Apache Software Foundation\Tomcat 5.0.



      4. JAVA_HOME: In the variable name field write JAVA_HOME, and in the variable value field write the location of JDK installation excluding bin as C:\Program Files\Java\jdk1.5.0_08.



  7. Write a small Servlet program to test the installation as follows:

    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;

    public class TestServlet extends HttpServlet
    {

       public void doGet(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException
       {
           response.setContentType("text/html");
           PrintWriter out = response.getWriter();
           out.println("<html>");
          out.println("<body>");
          out.println("This is a Servlet test!");
          out.println("</body>");
          out.println("</html>");
       }
    }


  8. Compile the Servlet file and put the class file in webapps/servlets/WEB-INF/classes directory inside the Tomcat directory.

  9. Open a new textpad file and write the following code:

    <web-app>
       <servlet>
           <servlet-name> TestServlet </servlet-name>
           <servlet-class> TestServlet </servlet-class>
       </servlet>

       <servlet-mapping>
           <servlet-name> TestServlet </servlet-name>
           <url-pattern>/test</url-pattern>
       </servlet-mapping>
    <web-app>

  10. Save the above textpad file as web.xml in the webapps/servlets/WEB-INF directory.

  11. Go to C:\Program Files\Tomcat 5.0\bin directory and start tomcat by double clicking on the startup batch file.


  12. Open a new instance of Internet Explorer and type the following URL in the Address bar:
    http://localhost:8080/servlets/test


Note: Whenever any change is made to the servlet, it should be compiled again. In such a case, either restart the Tomcat server or redeploy the application by going to http://localhost:8080/manager/html.


Rating:



Other articles

Click here to Article home

 
uCertify.com | Our Company | Articles | Privacy | Security | Contact Us | News and Press Release | uCertify India
MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD Cisco Certification: CCNA, CCENT, A+, Network+, Security+
Oracle Certification: OCP 9i, OCP 10g, OCA 9i, OCA 10g CIW foundation    EC-212-32    CISSP    Photoshop ACE    Adobe Flash ACE
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.