Java Server Page (JSP), and ASP, PHP are both network programming languages, but the script code inserted in the JSP page is a Java statement clip. To write applications using JSP, first, there must be a web server that can perform JSP scripts, which can be established on the basis of the original Apache, IIS or PWS server, but there are many technical issues. It is recommended to contact JSP's insects, or start a family, install a web server specially supported by JSP, so as not to have a branch, here, introduce Tomcat 3.1.
People who are familiar with online programming know that if there is no database support in network programming, it is quite hard. So what is better in the Java environment? At present, popular network databases have Oracle, Sybase, SQL Server, MySQL, etc., but the best Mysql for personal websites or small networks, which is completely free, easy to install, easy to manage, easy to get, fully support SQL language, etc. Features, for the current majority of network programming enthusiasts. This article describes how to install Java SDK, Tomcat, MySQL, JDBC for MySQL in a Windows environment.
Software preparation
The first thing you want to download below:
1, Java compile support environment: J2SDK1_3_-win.exe (30MB)
2, JDBC for MySQL driver: mm.mysql.jdbc-1.2b.zip (386KB)
3, support JSP web server Tomcat3.1: jakarta-to, cat.zip (2.23MB)
4, MySQL data stock server: mysql-3.23.21-beta-win-src.zip (2.23MB)
The above programs except the Mysql data inventory server, there are up-to-date programs in http://java.sun.com/, and it is easy to download in major downloads.
JSP development environment with jdbc for mysql installation
Install Java Development Kit
When the user accesses the JSP page of the Tomcat server, Tomcat first calls the Java development kit, compiles the Java code in the JSP page, and returns the result in HTML's format to customers. So before installing Tomcat, you must first install the Java Development Kit. Double-click the downloaded J2SDK1_3_0-win.exe directly to install, you can install the Java development environment. The only thing you need to operate is to select the installation directory, where it is assumed to be installed in the C: JDK1.3 directory.
In addition, if you choose Chinese's Windows, you must modify the system registry, because during the installation process, the system is used in Chinese registration "Java Runtime Environment", which is used to specify the directory of the files required for the Java runtime, and Java The SDK cannot identify Chinese data in the system registry.
The specific step is: open the registry with regedit and find the JavaSoft item, where: hkey_local_machine → Software → JavaSoft, find the Java Runtime Environment, and spread this branch to the file 1.REG. Then open the 1.Reg with a text editor, replace all of the "Java runtime environments" and save it, double-click the file to import the registry.
Then set an environment variable. In WIN 9X, you want to edit the autoexec.bat file, use the set statement to set the environment variable. In WIN NT or WIN 2000, you can choose "My Computer", right-click order, select "Properties", pop up the System Features dialog box, select "Advanced", then click "Environment Variable", you can edit the system The environment variable. Add a statement in it:
REM Settings Path
PATH =% path%; C: JDK1.3; C: JDK1.3in
REM sets Java environment variables
Set classpath = c: jdk1.3libtools.jar; c: jdk1.3libdt.jar;
REM Settings Java Home Directory
Set java_home = c: JDK1.3
Install Tomcat 3.1
Install Tomcat 3.1 is relatively simple, directly depressed JAKARTA-TOMCAT.ZIP to the C: Tomcat directory, then set the environment variable, add the following statement:
REM Settings Path
PATH =% path%; C: Omcat
REM set Tomcat environment variable
Set classpath = c: omcatclasses; c: omcatlib;% ClassPath
REM Sets Tomcat's home directory
Set Tomcat_Home = C: Omcat
After restarting the computer, you have a web server that supports JSP. Run the window of two command lines after Startup.bat running in the Tomcatbin directory. Type http: // localhost: 8080 in the browser, you should see the picture of Tomcat 3.1. By the way, don't turn these two windows, it is Java and Tomcat that is running in the background. To turn off the server to execute a C: Tomcatbin directory Shutdown.bat.
Install MySQL Database Management System
Unzip the downloaded mysql-3.23.21-beta-win-src.zip to a temporary directory, run the setup in the temporary directory, select the installation directory and installation mode according to the installation wizard, the system will complete the installation. It is assumed here to be installed in the C: MySQL directory. Run the mysqld-shareware.exe in the mysqlbin directory. You can start MySQL. After starting MySQL, there is no change in the Windows desktop, you can check if the database service is successfully installed by executing mysql manager. If the installation is successful, you can open the library TEST and MySQL inside.
Install JDBC for MySQL
In order to make Java can operate the MySQL database, you need to install the MySQL JDBC driver, extract mm.mysql.jdbc-1.2b.zip to C:, automatically generate a directory of mm.mysql.jdbc-1.2b, and set Environment variable:
REM set mysql.jdbc environment variable
Set classpath = c: mm.mysql.jdbc-1.2b;% classpath
After restarting, all installations are all OK!
Example: Establish a message on the environment
Establish a table that stores data
To design a message book, you must first create a table that stores message data in MySQL's database, assumes that the table is Questbook, and its structure is as follows:
Recordid storage record number
Name stores the name of the message
Email stores the message address of the message
Body stores message
Specific steps:
1. Execute the program mysqld-shareware.exe to start MySQL.
2. Execute the program mysqlmanager to open the library Test.
3. Select SQL Query under the Tools menu and appear in the Mysql Query window. 4. Under the Query tab, the input command is as follows: Create Table Questbook (RecordId Int, Name Char (20), Email Char (30), Body Text).
5. Click Run icon. You can get table Questbook for storing message book data.
Write a message book program
Java is an API function in the toolkit provided by JDBC for MySQL to call the mysql database, you can open the C: mm.mysql.jdbc-1.2bdocapidocindex.html file with your browser to get all API functions. Below I only introduce you a few functions required to write a message book.
Class.Forname ("org.gjt.mm.mysql.driver"); used to load mm.mysql driver
Con = DriverManager.getConnection ("JDBC: MySQL: // LocalHost: 3306 / Test? User = root; password ="); used to connect local database MySQL
STMT = con.createstatement (); generates database objects
RS = stmt.executeQuery ("Select * from guestbook"); execute SQL statement and return result set
Place the program after the release of Tomat's release catalog C: TomcatWebAppsroot is ok.