1. Download to the Sun Homepage Download the JDK installation version, assuming that the JDK is installed in C: /J2SDK1.4.2_03/, then set the environment variable java_home as C: /J2SDK1.4.2_03/, and then add C: / J2SDK1 in the environment Path variable. 4.2_03 / bin; add Tools.jar and Dt.jar in the ClassPath environment variable, if there is no ClassPath environment variable, create it. 2. Download the Tomcat installation version, assuming Tomcat is installed in c: /tomcat4.1; then set the environment variable Catalina_home is C: /Tomcat4.1; simultaneously add C: /Tomcat4.1/bin to the PATH environment variable. When you install Tomcat, you will be prompted to enter the password of Admin. This password is used to configure Tomcat. 3. Execute Catalina_Home / Bin / Startup.bat, launch Tomcat. Open the IE browser, type http: // localhost: 8080 / (guarantee port not to conflict with other server). "Tomcat Administration" appears on the left side of the page, "Tomcat Manager" two connections. 4. Create a web-inflicity under the C: / Establishing the Webroot directory, establish a web-infer in WebRoot, and establish a web.xml file in Web-INF. Edit Web.xml file, enter: Xml version = "1.0" eNCoding = "ISO-8859-1"?>
The following describes how to use JSP and servlets. 1. We build helloworld.jsp under C: / Webroot, enter the following:
2. We created a servlet, named myServlet1.java, put under the C: / Webroot / SRC, the input content is as follows: import javax.servlet. *; Import javax.servlet.http. *; Import java.io. *; Import java.util. *;
/ ** *
Title: p> *
Description: p> *
Copyright: Copyright (c) 2003 p> *
Company: p> * @ Author not attributable * @version 1.0 * /
public class MyServlet1 extends HttpServlet {private static final String CONTENT_TYPE = "text / html; charset = GBK"; // Initialize global variables public void init () throws ServletException {} // Process the HTTP Get request public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {response.setContentType (CONTENT_TYPE); PrintWriter out = response.getWriter (); out.println ( ""); out.println ( "
the servlet Has Received A Request.getMethod () ". This is the reply p> "); out.println (". body> html> ");} // Process the HTTP Post request public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {Doget (Request, Response);} // clean up resources public void design () {}} 3. Open web.xml (where you know it), editing as follows: XML Version = "1.0" encoding = " ISO-8859-1 "?>
4. Compile Servlet: Create a lib directory in C: / Webroot / Web-INF / C: C: / Tomcat 4.1 / Common / lib / servlet.jar to the lib directory. Create a classes directory in C: / Webroot / Web-INF /. The Complier.bat content is built in C: / Webroot / below: javac -classpath ./web-inf/lib/servlet.jar; ./src/*.java -d ./web-inf/classespause runs company.bat Re-re- Start Tomcat, open the browser to knock http: // localhost: 8080 / Webroot / MyServlet1, execute, if it is the reply. "Indicates that the execution is successful.