J
Justin L. Davidson
HOW-TO: Create Servlets
Step 1: (add servlet mapping in web.xml to class)
--- /usr/local/jakarta-tomcat-4.0.4/webapps/ROOT/WEB-INF/web.xml --
<?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>HelloWorld</servlet-name>
<servlet-class>hall.HelloWorld</servlet-class>
</servlet>
</web-app>
Step 2: (create and compile java class)
-- /usr/local/jakarta-tomcat-4.0.4/webapps/ROOT/WEB-INF/classes/HelloWorld.class
--
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Hello World");
}
}
Step 3: (restart servlet container)
/usr/local/jakarta-tomcat-4.0.4/bin/shutdown.sh
/usr/local/jakarta-tomcat-4.0.4/bin/startup.sh
Step 4: (test application in browser)
http://justin.ctcnet.com:8080/servlet/HelloWorld
Good Luck!
(e-mail address removed)
Step 1: (add servlet mapping in web.xml to class)
--- /usr/local/jakarta-tomcat-4.0.4/webapps/ROOT/WEB-INF/web.xml --
<?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>HelloWorld</servlet-name>
<servlet-class>hall.HelloWorld</servlet-class>
</servlet>
</web-app>
Step 2: (create and compile java class)
-- /usr/local/jakarta-tomcat-4.0.4/webapps/ROOT/WEB-INF/classes/HelloWorld.class
--
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Hello World");
}
}
Step 3: (restart servlet container)
/usr/local/jakarta-tomcat-4.0.4/bin/shutdown.sh
/usr/local/jakarta-tomcat-4.0.4/bin/startup.sh
Step 4: (test application in browser)
http://justin.ctcnet.com:8080/servlet/HelloWorld
Good Luck!
(e-mail address removed)