(Reposted) Configuration of JSP, Servlet, and JavaBean Environment under Tomcat
I often see the JSP's beginners ask how to configure JSP, servlet, and bean under Tomcat, so I have summarized how JSP, servlet, and beans are configured under Tomcat, I hope to help those beginners. Step 1: Download J2SDK and Tomcat: to the Sun Official Site (http://java.sun.com/j2se/1.4.2/down ... Load version of the SDK for Windows Offline Installation, and best download J2SE 1.4. 2 Documentation, then go to Tomcat Official Site (http://www.apache.org/dist/jakarta/tomcat); Step 2: Install and configure your J2SDK and Tomcat: Perform J2SDK and Tomcat installer, then press by default Setting up. 1. After installing J2SDK, you need to configure the environment variable, add the following environment variables in My Computer -> Properties -> Advanced -> Environment Variables -> System Variable (assuming your J2SDK installed in C: /J2SDK1.4.2): java_home = c: /j2sdk1.4.2 classpath =.;% java_home% / lib / dt.jar;% java_home% / lib / Tools.jar; (.; must not be less, because it represents the current path PATH =% java_home% / bin then writes a simple Java program to test whether J2SDK has been installed successfully: public class test {public static void main (string args []) {system.out.println ("this is a Test Program. ");}} Save the above program as file named Test.java. Then open the command prompt window, CD to your Test.java, then type the following command Javac Test.java Java Test At this time, if you see this is a test program. If you have successful installation, if you don't print this sentence, you need to check your configuration carefully.
2. After installing Tomcat, add the following environment variables in my computer -> Properties -> Advanced -> Environment Variables -> System Variables (assuming your Tomcat is installed in C: / Tomcat): Catalina_Home = C: / Tomcat; Catalina_Base = C: / tomcat; then modify the classpath in the environment variable, add servlet.jar under the Tomat installation directory to the ClassPath, the modified ClassPath is as follows: classpath =.;% java_home / lib / Dt.jar;% java_home% / lib / Tools.jar;% catalina_home% / common / lib / servlet.jar; then you can start Tomcat, access http: // localhost: 8080 in IE: establish your own JSP APP Directory 1. WebApps directory for the Tomcat installation directory, you can see the directory of Tomcat, which root, example, tomcat-docs. 2. Create a directory in the WebApps directory, named myapp; 3.myapp Create a directory web-inf, note that the directory name is case sensitive; 4.Web-INF Newly built a file web.xml, the content is as follows: XML Version = "1.0" eNCoding = "ISO-8859-1" ?>
Step 4: Establish your own servlet: 1. Creating a servlet program with your most familiar editor (recommended using syntax-check Java IDE), the file name is Test.java, the file content is as follows: package test; import Java. io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class Test extends HttpServlet {protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {PrintWriter out = response.getWriter (); out.println ( "
Now WebApps / MyApp / Web-INF / CLASSES has the file directory structure 4. Modify WebApps / MyApp / Web-INF / Web.xml, add servlet and servlet-mapping, Web.xml as follows Sign, red is added: XML Version = "1.0" encoding = "ISO-8859-1">