Configure the Web application environment to implement JSP message book

Source: Internet
Author: User

Java Server Page (JSP for short) is a network like ASP and PHP. Programming Language , But the script inserted in the JSP page Code 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 theseProgram:

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.