I am learning servlet programming and I have not gotten to display a page
properly. It is quite frustrating because I get a message that the
page does not exist.
I start tomcat, load IE, and try the URL
http://localhost:8080/myApp/servlet/Primitive
Primitive is the name of the servlet I want to run.
I am using IE 5.5, WIN2000 sp4, jsdk1.4, tomcat 4.1
I followed all the instructions to install and set tomcat.
Under c:\tomcat\webapps I created a directory named myApps and
inside it I created a dir name WEB-INF. In this directory I have created
a dir named classes and a file named web.xml.
My classpath and path are set for:
JAVA_HOME = c:\j2sdk1.4.1_02
path = %PATH%;%JAVA_HOME%\\bin
CLASSPATH =
.;%JAVA_HOME%\bin;c:\jakarta-tomcat-4.1.30\common\lib\servlet.jar
The codes are (actually they were taking from a book)
import javax.servlet.*;
import java.io.IOException;
public class PrimitiveServlet implements Servlet {
public void init(ServletConfig config) throws ServletException {
System.out.println("init");
}
public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException {
System.out.println("service");
}
public void destroy() {
System.out.println("destroy");
}
public String getServletInfo() {
return null;
}
public ServletConfig getServletConfig() {
return null;
}
}
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>Primitive</servlet-name>
<servlet-class>PrimitiveServlet</servlet-class>
</servlet>
</web-app>