Configure the Web application environment to implement JSP guestbook _ MySQL

Source: Internet
Author: User
JavaServerPage (JSP for short) is a network programming language like ASP and PHP, but the script code inserted on the JSP page is a Java statement segment. To use JSP to write applications, you must first have a Web server that can execute JSP scripts, which can be created on the basis of the original Apache, IIS, or PWS server, however, there are many technical problems. We recommend that you just connect Java Server Page (JSP for short) is a network programming language like ASP and PHP, but the script code inserted on the JSP Page is a Java statement segment. To use JSP to write applications, you must first have a Web server that can execute JSP scripts, which can be created on the basis of the original Apache, IIS, or PWS server, however, there are many technical problems. We recommend that you install a Web server that supports JSP directly from scratch, so as to avoid future development. here we will introduce Tomcat 3.1.

Anyone familiar with network programming knows that, without database support in network programming, it would be quite hard to do a very simple task. Which database is better to use in the Java environment? Currently, popular network databases are mainly Oracle, Sybase, SQL Server, MySQL, etc. However, MySQL is the most suitable for personal websites or small networks, it is completely free, easy to install, easy to manage, easy to get, full support for SQL language and other features, for the majority of network programming enthusiasts like. This article describes how to install Java SDK, Tomcat, MySQL, and JDBC for MySQL in Windows.

   Software preparation
First, download these programs:

1. java compilation support environment: j2sdk1_3_-win.exe (30 MB)

2. JDBC for MySQL driver: mm.mysql.jdbc-1.2b.zip (small KB)

3. support for JSP Web servers Tomcat3.1: jakarta-to,cat.zip (2.23 MB)

4. MySQL data inventory server: mysql-3.23.21-beta-win-src.zip (2.23 MB)

In addition to the MySQL data inventory server, the above programs are available in the latest versions at http://java.sun.com/, and are easily downloaded from various download centers.

   Install a JSP development environment with JDBC for MySQL
   Install Java Development Kit
When you access the JSP page of the Tomcat server, Tomcat first calls the Java Development Kit, compiles and executes the Java code on the JSP page, and returns the result to the customer in HTML format. Therefore, you must install the Java Development Kit before installing Tomcat. Install j2sdk1_3_0-win.exe directly to install the Java development environment. the only operation required is to select the installation directory, which is assumed to be installed in the C: \ JDK1.3 directory.

In addition, if you use a Chinese Windows system, you must modify the system registry, because during the installation process, the system registers the "Java Runtime Environment" branch in Chinese, this branch is used to specify the directory of files required for Java runtime, and Java SDK cannot recognize Chinese data in the system registry.

The procedure is as follows: use RegEdit to open the registry and find the secret oft entry. The location is hkey_local_machine → software → export oft. find "Java Runtime Environment" and export this branch to File 1. reg. Open 1.regin in the text editor, replace all "Java Runtime Environment" with "Java Runtime Environment", save the settings, and double-click the File to import it to the registry.

Set the environment variables. In Win 9x, edit the Autoexec. bat file and use the Set statement to Set the environment variable. In Win NT or Win 2000, you can select "My Computer", right-click the menu, and select "properties". The "system features" dialog box is displayed, and select "advanced ", click "environment variables" to edit the system environment variables.

Add the following statement:

Rem setting path

PATH = % PATH %; c: \ jdk1.3; c: \ jdk1.3 \ bin

Rem sets java environment variables

Set CLASSPATH = C: \ jdk1.3 \ lib \ Tools. jar; C: \ jdk1.3 \ lib \ dt. jar;

Rem sets the java main directory

Set JAVA_HOME = c: \ jdk1.3

   Install Tomcat 3.1
The installation of Tomcat 3.1is relatively simple. directly extract jakarta-tomcat.zip and release it to the C: \ Tomcat Directory. Then, set the environment variables and add the following statement:

Rem setting path

PATH = % PATH %; c: \ tomcat

Rem sets tomcat environment variables

Set CLASSPATH = c: \ tomcat \ classes; c: \ tomcat \ lib; % CLASSPATH

Rem sets the main directory of TOMcat

Set TOMCAT_HOME = c: \ tomcat

After you restart your computer, you have a Web server that supports JSP. After running Startup. bat in the C: \ Tomcat \ Bin directory, two command line windows are displayed. In this case, type http: // localhost: 8080/in the browser, and you will be able to see the Tomcat 3.1 screen. By the way, do not close these two windows. it indicates that Java and Tomcat are running in the background. To disable the server, run Shutdown. bat in the C: \ Tomcat \ Bin directory.

   Install the MySQL database management system
Decompress the downloaded mysql-3.23.21-beta-win-src.zip file to a temporary directory, run Setup in the temporary directory, and select the installation directory and installation method according to the installation wizard. The system will complete the installation. It is assumed that the installation is in the C: \ MySQL directory. Run mysqld-mongoware.exe in the C: \ MySQL \ Bin \ directory to start MySQL. After MySQL is started, the Windows desktop remains unchanged. you can run MySQL Manager to check whether the database service is successfully installed. If the installation is successful, you can directly open the database Test and MySQL.

   Install JDBC for MySQL
To enable Java to operate the mysql data library, install the JDBC driver of mysql, extract mm.mysql.jdbc-1.2b.zip to C: \, automatically generate a directory of mm. mysql. jdbc-1.2b, and set environment variables:

Rem sets mysql. jdbc environment variables

Set CLASSPATH = c: \ mm. mysql. jdbc-1.2b; % CLASSPATH

After the restart, all the installation will be OK!

   Example: use the environment to create a message book
   Create a table to store data
To design a message book, you must first create a table for storing the message data in the MySQL database. assume that the table is Questbook and its structure is as follows:

Recordid

Name: name of the message holder

Email stores the Email address of the message recipient

The body stores the message of the message recipient.

Procedure:

1. execute the mysqld-mongoware.exe program to start MySQL.

2. execute the program MySQLManager and open the library Test.

3. select SQL Query in the Tools menu. the MySQL Query window is displayed.

4. enter the following command under the Query tag: create table questbook (Recordid int, Name char (20), Email char (30), Body text ).

5. click the run icon. You can get the Questbook used to store the message book data.

   Compile the guestbook program
Java calls the MySQL database through the API function in the toolkit provided by JDBC for MySQL. you can open C: \ mm in a browser. mysql. the jdbc-1.2b \ doc \ apidoc \ index.html file to get all the API function instructions. Below I will only introduce you to the functions required for writing the message book.

Class. forName ("org. gjt. mm. mysql. Driver"); used to load the mm. mysql Driver

Con = DriverManager. getConnection ("jdbc: mysql: // localhost: 3306/test? User = root; password = "); used to connect to the local database MySQL

Stmt = con. createStatement (); generate database object

Rs = stmt.exe cuteQuery ("SELECT * FROM guestbook"); execute the SQL statement and return the result set

Compile the program and place it in the Tomat release directory C: \ Tomcat \ webapps \ ROOT.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.