How to install and configure Tomcat for Windows(tm)
September 17th, 2008 by uCertify Leave a reply » To install and configure Tomcat, you will have to take the following steps:- Download JDK 1.5 from Sun(tm) site at http://java.sun.com/javase/downloads/index_jdk5.jsp
- Install JDK to C:Program FilesJavajdk1.5.0_08
- Download Tomcat 5 from http://tomcat.apache.org/download-55.cgi
- Install Tomcat on C:Program FilesApache Software FoundationTomcat 5.0
- 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.
- 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:
- 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 FilesApache Software FoundationTomcat 5.0commonlibservlet-api.jar
- Path: In the variable name field write PATH, and in the variable value field write the location of JDK installation as C:Program FilesJavajdk1.5.0_08bin;.;
- 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 FilesApache Software FoundationTomcat 5.0.
- 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 FilesJavajdk1.5.0_08.
- 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>”);
}
} - Compile the Servlet file and put the class file in webapps/servlets/WEB-INF/classes directory inside the Tomcat directory.
- 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> - Save the above textpad file as web.xml in the webapps/servlets/WEB-INF directory.
- Go to C:Program FilesTomcat 5.0bin directory and start tomcat by double clicking on the startup batch file.
- Open a new instance of Internet Explorer and type the following URL in the Address bar:
http://localhost:8080/servlets/test
Note by Rehan:
it was not being compiled. so I changed the name from servlet-api.jar to servlet.jar and made changes accordingly in classpath. then it started working fine.
No comments:
Post a Comment