Configure Web application environment to implement JSP guest book development

Source: Internet
Author: User
Tags mysql in mysql query stmt zip mysql database tomcat tomcat server


Java Server page (JSP), like ASP and PHP, is a network programming language, except that the scripting code inserted in a JSP page is a fragment of a Java statement. To use JSP to write an application, first of all, must have a Web server that can execute JSP script, can build on the original Apache, IIS or PWS server, but there are many technical problems. It is recommended that just contact JSP bugs, or from scratch, directly install a dedicated Web server to support JSP, lest complications, here to introduce you are Tomcat 3.1.

people familiar with network programming know that without the support of the database in network programming, a very simple thing to do is quite hard. So what database is better to use in the Java environment? At present, the popular network databases are mainly Oracle, Sybase, SQL Server, MySQL, etc., but the most suitable for personal web sites or small network use of the most important MySQL, its completely free, easy to install, easy to manage, easy to obtain, fully support the characteristics of SQL language, For the current vast number of network programming enthusiasts like. This article describes how to install the Java SDK, Tomcat, MySQL, JDBC for MySQL in a Windows environment.

Software prepares

to first download to the following programs:

1, Java Compilation support environment: J2sdk1_3_-win.exe (30MB)

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

3, JSP-enabled Web server Tomcat3.1:jakarta-to,cat.zip (2.23MB)

4, MySQL Data Inventory server: Mysql-3.23.21-beta-win-src.zip (2.23MB)

The above program, in addition to the MySQL data Inventory server, in the http://java.sun.com/has the latest version of the program, In the major download centers are also easy to download.

Install the JSP development environment with JDBC for MySQL

Install Java Development Kit

When a user accesses the JSP page of a Tomcat server, Tomcat invokes the Java Development Kit first. Compiles and executes the Java code in the JSP page and returns the results to the customer in HTML format. Therefore, before you install Tomcat, you must first install the Java Development Kit. Double-click When installingDownload the J2sdk1_3_0-win.exe, you can install the Java development environment, the only thing that needs to be done is to select the installation directory, which is assumed to be installed in the c:jdk1.3 directory.

In addition, if you choose Windows in Chinese, you must modify the system registry, because during installation, the system registers the branch of the Java Runtime Environment in Chinese, which indicates the directory of the files required by the Java runtime, and the Java The SDK does not recognize the Chinese data in the system registry.

The specific step is to open the registry with Regedit and locate the JavaSoft entry, located at: Hkey_local_machine→software→javasoft, to find the Java runtime environment. Export this branch to file 1.reg. Then open the 1.reg with a text editor, replace all of the "Java Runtime Environment" with "Java Runtime environment" and save, and double-click the file to import the registry. The

then sets the environment variable. In Win 9x, to edit the Autoexec.bat file, set the environment variable with the SET statement. In Win NT or Win 2000 you can choose "My Computer", right-click the menu, select "Properties", pop-up "System Features" dialog box, select Advanced, and then click the button "Environment variables", you can edit the system's environment variables. The

adds the following statement: 


rem set path PATH =% PATH%; c: jdk1.3; c: jdk1.3bin rem set java environment variable set CLAS
SPATH = C: jdk1.3libTools.jar; C: jdk1.3libdt.jar; rem Set java home directory set JAVA_HOME = c: jdk1.3


Install Tomcat 3.1

Installation Tomcat3.1 relatively simple, directly jakarta-tomcat.zip decompression released to the C:tomcat directory, and then set the environment variable, add the following statement:


rem set path PATH =% PATH%; c: tomcat rem set tomcat environment variable set CLASSPATH = c: tomcatcla
sses; c: tomcatlib;% CLASSPATH rem set TOMcat's home directory set TOMCAT_HOME = c: tomcat


After you restart your computer, you have a Web server that supports JSP. A window in which two command-line methods appear after running the C:tomcatbin directory Startup.bat. When you type http://localhost:8080/in the browser, you should see the image of Tomcat 3.1. By the way, don't turn off the two windows, which means Java and Tomcat are running in the background. To shut down the server executable 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 setup in the Temp directory, and choose the installation directory and installation method according to the Installation wizard, the system will complete the installation. This is assumed to be installed in the C:mysql directory. Run the Mysqld-shareware.exe in the C:mysqlbin directory to start MySQL. After you start MySQL, the Windows desktop does not change, and you can check that the database service was successfully installed by executing MySQL manager. If the installation is successful, you can directly open the inside of the library test and MySQL.

Installing JDBC for MySQL

To enable Java to operate MySQL's database, you need to install the MySQL JDBC driver, extract mm.mysql.jdbc-1.2b.zip to C:, automatically generate a mm.mysql.jdbc-1.2b directory, and set the environment variables:


rem set mysql.jdbc environment variable set CLASSPATH = c: mm.mysql.jdbc-1.2b;% CLASSPATH



After the restarts, all the installations are OK! 、


Example: Create a guest book using an environment 




create a table to hold data

to design a guest book, you must first create a table in the MySQL database that holds the message data, assuming that the table is Questbook and has the following structure:

RecordID Store the record number

Name The name of the person who left the message

Email address of the message to the message

message in the body store message

Specific steps:

1. Executive Program Mysqld-shareware.exe, start MySQL.

2. Execute program mysqlmanager, open Library test.

3. Select SQL Query under the Tools menu and the MySQL query window appears.

4. Under the Query tab, the input commands are as follows: Create TABLE Questbook (RecordID int,name char (), Email char (), body text).

5. Click the Run icon. You can get a table Questbook for storing guest book data.

to write the guest book program

Java is to invoke the MySQL database by using the API function in the toolkit provided by JDBC for MySQL, you can open the C: mm.mysql.jdbc-1.2bdocapidocindex.html file to obtain all API function descriptions. Let me just introduce you to a few of the functions you need to write a guest book.



Class.forName ("Org.gjt.mm.mysql.Driver"); Used to load mm.mysql driver con = driverman
ager.getconnection ("jdbc:mysql:// Localhost:3306/test?user=root;password= "); used to connect
to the local database MySQL stmt = con.createstatement (); Build database Object rs = Stmt.executequery ("SELECT * from Guestbook"),
Row SQL statement, and return result set



After you have compiled the program, put it in the Tomat release directory c:tomcatwebappsroot.


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.