I have just started learning JSP, I want to put some experience in the configuration Tomcat. 1. Environment Variable Configuration First Install JDK and Tomcat, and then configure environment variables. Environmental variables in my computer Right-click -> Properties -> Advanced -> Environment Variables, SET is written according to DOS's batch command, you can do not need to manage, just know the meaning behind SET, then give lazy people One way.
/ * set java_home = E: /Tools/environment/java/j2sdk1.4.2_05set catalina_home = E: / TOOLS / Environment / Java / Tomcat 5.0set ClassPath =.;% java_home% / lib / dt.jar;% java_home / Lib / Tools.jar;% catalina_home% / common / lib / servlet-api.jar;% catalina_home% / common / lib / mssqlserver.jar;% catalina_home% / common / lib / msbase.jar;% catalina_home% / Common / LIB / MSUTIL.jar;% catalina_home% / WebApps / JSPBBS / Web-INF / CLASSESSET PATH =% PATH%;% java_home% / bin * /
This is the environment variable I have, and I will explain one by one. Let me talk about% percentage.% Java_home% percent sign is actually the value corresponding to this variable, such as:
Set java_home = c: set java_home =% java_home%; D:
Also equivalent to set java_home = c: set java_home = C:; D:
Here% java_home% is actually equal to C:
1. set java_home = E: /Tools/environment/java/j2sdk1.4.2_05 Set the JDK installation directory, the environment variable is set to java_home, if your JDC is installed in c: /j2sdk1.4.2_05 then java_home = C: /J2SDK1.4.2_05
2. SET CATALINA_HOME = E: / Tools / Environment / Java / Tomcat 5.0 Sets the Tomcat installation directory, and the same
3. ClassPath =.;% Java_home% / lib / dt.jar;% java_home% / lib / tools.jar;% catalina_home% / common / lib / servlet-api.jar;% catalina_home% / common / lib / mssqlserver. JAR;% catalina_home% / common / lib / mssqlser.jar;% catalina_home% / common / lib / msutil.jar;% catalina_home% / webapps / jspbbs / web-inf / classdt.jar and Tools.jar are two to be included A package file, * Of course, don't forget to join the beginning. "Indicates that the current directory * I use Tomcat is 5.0, so the servlet file is servlet-api.jar instead of servlet.jar, Tomcat5.0, please ask friends Contains servlet.jar instead of servlet-api.jarmsqlser.jar, msbase.jar, msutil.jar These three files are SQL Server driver files. If it is another database, you may have to join the appropriate database driver file. Database driver files should go online to go online
4.% Catalina_Home% / WebApps / JSPBBS / Web-INF / CLASSES is the Class directory you store servlet and bean. If the servlet is available, you must add this. 5. SET PATH =% PATH%;% java_home% / bin This is the directory where you set the two commands of your Javac and Java. If you don't set it, if I want to run a .java file, I have to run E: /Tools/environment/java/j2sdk1.4.2_05/bin/javac sample.java huh, every time you have this, it's trouble. of.
Speaking of the lazy method, you can save me a start / *...*/ save the variables to autoexec.bat is placed in the C-drive root directory (if your boot disk is other, then put it in In the corresponding disk), this will save the process of configuring environment variables.
The basic configuration of the environment variable here is completed.
II. XML file configuration Next Configure server.xml in% CATALINA_HOME% / confation, back up before configuring 1. Port Configuration (Optional) Find below 2. Auto overload, if the class changes, Tomcat will be overloaded without restarting Tomcat to find the following paragraph 3. Start the root context to find the following paragraph " "below it below." DOCBASE = "root" debug = "0" /> -> * Note that tomcat5.0 seems to be the Next to configure web.xml Note this web.xml is Web.xml in% catalina_home% / confed, not Web.xml under Web-INF under your project directory, first back up Web.xml1. Open the servlet call, You don't have to configure servlets in Web-INF / Web.xml, you can call servlet to find the following paragraph ├─Web-INF│ ├─Web.xml│ └─classes│ └─ └─ The JSP engineering directory structure is basically written in a servlet. Import javax.servlet. *; import javax.servlet.http. *; import java.io. *; public class MyServlet extends HttpServlet {public void doGet (HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {PrintWriter out = response.getWriter (); out.println ( "Hello World!");}} compiler that the WEB-INF / classes My engineering directory is jspbbs, then running servlet is http: // localhost / jspbbs / servlet / myservlet because it is used to use the servlet automatic caller, so all servlet is running in front of the / servlet If there is a package, http: // localhost / jspbbs / servlet / package name .myservlet