Reason: In the vast Internet, I cannot find the latest integration configuration document of Mysql4.0.13 and Tomcat4.1.24. In my spare time, I summarized my actual experience in building a JSP environment and wrote this configuration document with reference to previous versions of Mysql and Tomcat related configuration articles. I hope it can be used as a reference for beginners who like JAVA as much as I do, so as to avoid taking some detours; my level is limited and my time is short, so any corrections are welcome!
Contents:
1. Software preparation
2. Software installation
3. Initial configuration and testing
4. Integrated configuration
5. Full line test
6. Supplementary instructions
7. Thank you
8. Instructions
Specific implementation steps:
1. Software preparation:
Assume that you have a hardware and software environment that can run win2000 normally.
1.J2sdk1.4.1: Go to [url]http://java.sun.com/j2se/1.4.1/download.html[/url] to download;
2.Mysql4.0.13: Go to [url]http://www .mysql.com[/url] Download;
3.Tomcat4.1.24: Go to [url]http://jakarta.apache.org/[/url] to download;
4.mm.mysql-2.0.4-bin.jar: Go to [url]http://mysql.ihostunit.com/Downloads/Contrib/mm.mysql-2.0.4-bin.jar[/url] to download;
2. Software installation:
1. Install J2sdk:
Follow the installation wizard to install (generally install to C:j2sdk1.4.1 for easy operation);
2. Install Mysql:
Follow the installation wizard to install (select the installation directory as C:, Easy to operate; after successful installation, the path is: C:mysql);
3. Install Tomcat:
Follow the installation wizard to install (change the installation directory to C:Tomcat4.1, during which you will be asked to enter Admin (system administrator) Password);
4. Place the Jdbc driver of Mysql:
put the mm.mysql-2.0.4-bin.jar file under C:j2sdk1.4.0-rclib (actually it doesn’t matter where you put it, mainly in the system Just point it in the variable, but many people said it would be better to put it here, so I put it here);
3. First-time configuration and testing:
Configure the software environment installed above for the first time, and test its environment:
(1) Configuration--Environment variables:
1. Create a new system variable JAVA_HOME, its value is: C:j2sdk1.4.1 (if If you did not install according to the above path, please change
it to your installation path); 2. Create a new system variable TOMCAT_HOME, its value is: C:Tomcat4 (If you did not install it according to the above path, please change it to your installation path);
3. System Variable CLASSPATH, add, its value is: C:Tomcat 4.1commonclasses;C:Tomcat 4.1commonlib
4. System variable CLASSPATH, add, its value is: C:j2sdk1.4.0-rclib mm.mysql-2.0.4-bin;
(2) Test the default service:
1. Please start Tomcat4.1 first (find Apache Tomcat4.1 in Start-Program to run Start Tomcat) service:
open the browser and enter in the address bar: [url]http://localhost :8080[/url] Verification: You can see the Tomcat welcome interface in the browser at this time. It means that Tomcat is working normally (note that the default port of Tomcat is 8080, if it is occupied by other programs, please change it);
2. Start the Mysql service (Mysql service starts with the operating system by default, and winmysqladmin.exe is minimized on the system tray):
Enter CMD, go to the C:mysqlbin directory, execute mysql, and press Enter. If normal, some welcome messages will be output, indicating that Mysql Works fine;
4. Integrated configuration:
Configure Mysql4 and Tomcat4 accordingly and let them work together for you:
1. Copy mm.mysql-2.0.4-bin.jar to Tomcat’s common/lib directory;
2. Test whether the connection is Normal; save the following code as test.jsp to the C:Tomcat 4.1webappsROOT directory:
<%@ page contentType="text/html;charset=gb2312" %>
<%
java.sql.Connection conn;
java.lang.String strConn;
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn= java.sql.DriverManager.getConnection("jdbc:mysql://localhost/test","root","");
%>
<%--What is connected here is the test library that comes with Mysql4 by default. The user and password are the default root and empty --%>
3. Enter [url]http://localhost:8080 in the browser address. /test.jsp[/url] If a blank page appears after running, it means that the integration of Mysql4 and Tomcat4 is successful;
5. Full line test:
1. Start Tomcat4.1;
2. Create database and tables;
first create a table in mysql and insert several pieces of data. The sql code is as follows:
create database test;--Run
use test;--Run
create talbe admin (id int(4) auto_increment primary key,name varchar(20));--Run
INSERT INTO user(name) VALUES('test');--Run
ok, you have created the database test, created the table user, and inserted a record.
3. Display the records in the database;
save the following code as test2.jsp to the C:Tomcat 4.1webappsROOT directory:
<%@ page contentType="text/html;charset=GBK" %>
<%@ page language="java" import="java.sql.*"%>
<%
Connection conn = null;
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = java.sql.DriverManager.getConnection("jdbc:mysql://localhost/test","root","");
if(conn==null){
System.out.println("get Conn Error");
}
Statement stmt=conn.createStatement();
ResultSet RS_result=null;
%>
<html>
<head>
<title>Test</title></head>
<body>
<%
RS_result=stmt.executeQuery("select * from user");
String Name;
while(RS_result.next())
{
Name=RS_result.getString("name");
%>
<%=Name%>
<%
}
RS_result.close();
stmt.close();
conn.close();
%>
</body>
</html>
4. Open your browser and enter [url]http://localhost:8080/test.jsp[/url] in the address bar. If test is displayed on the page after running, it means that the database is read successfully. ;
6. Supplementary instructions:
1. Assume that there is already a project in the E:testoa directory (including index.jsp and other jsp files and beans, such as servlets and javabeans under WEB-INFclasses);
To set up Tomcat to support your project, open the C:Tomcat4.1confserver.xml file and add it before "</Host>" and after "</Context>"
<Context path="/oa" debug="0" docBase="E:testoa" reloadable="true"/>and save.
Description: Context (representing a web application): docBase defines the path of the application; path represents the prefix of the URL of this web application, so that the requested URL
This attribute is [url]http://localhost:8080/oa[/url]; reloadable. This attribute is very important. If it is true, tomcat will automatically detect the application's /WEB-INF/lib
and changes in the /WEB-INF/classes directory, automatically loading modified or new beans and servlets. We can see the changes brought to jsp by beans without restarting tomcat;
2. Start Tomcat 4.1, in the browser Enter [url]http://localhost:8080/oa[/url] in the address. If there are no errors in jsp and beans, your index.jsp/index.html will generally be
The contents of the file are executed and displayed.
7. Thanks:
1. Thanks to the Apache and Mysql organizations for providing such good free application servers and databases;
2. Thanks to friends who have written Tomcat3.x/Tomcat4.* configuration documents before for writing them for me today. This document is used as a reference;
8. Instructions:
1. If you are satisfied and want to reprint or collect this article, I would like to thank you very much, but please indicate the author hoxisoft ( [email protected] )