JSP, J2SDK, Tomcat, connection SQL Server 2000 full system configuration

xiaoxiao2021-03-06  82

Step 1: ---- Install J2SDK:

To the Sun Official Site (http://java.sun.com) Download the J2SDK installation file: J2SDK-1_4_2_04-windows-i586-p.exe, after download

Install J2SDK;

After installation, set the environment variable: my computer --- Properties - Advanced - Environmental Variables;

Select --- System Variable (s):

Set the java_home environment variable:

Click - New, enter: java_home in the variable name

Enter: D: / Java in the variable value

(Suppose J2SDK is installed under the directory D: / java, anyway is the J2SDK installation directory.)

Then --- OK, you have set a Java_Home environment variable.

Set the ClassPath environment variable:

Click - New, enter: ClassPath in the variable name

Enter: d: / java / lib; d: /java/lib/tt.jar; D: /java/lib/tools.jar

(Middle point "." And semicolons ";" essential.)

Then --- OK, you have set the ClassPath environment variable.

Set the PATH environment variable:

Click - New, enter: path in the variable name: Path

Enter: D: / java / bin in the variable value;

(Middle point "." And semicolons ";" essential.)

Then --- OK, you have set a Java_Home environment variable.

After the three environment variables are set, write a simple Java program to test whether J2SDK has been installed successfully:

Create a directory TEST in D: / Next procedure:

Public class test {

Public static void main (string args []) {

System.out.println ("This Is A Test Program.");

}

}

Save the above program as file named Test.java, saved under the directory D: / Test.

Then open the command prompt window, CD to your TEST directory, and type the following command

Javac Test.java

Java Test

At this point, if you see the THIS A Test Program. If you have successful installation,

If you don't print this sentence, you need to check your configuration carefully.

If the J2SDK is installed in the above, let's continue to install Tomcat:

Step 2: ---- Install Tomcat:

To Tomcat Official Site (http://www.apache.org/dist/jakarta/tomcat-4/) download Tomcat:

JAKARTA-TOMCAT-4.1.30.EXE, after downloading. (Such as installed under D: / Tomcat.)

After installation, set the environment variable: my computer --- Properties - Advanced - Environmental Variables;

Select --- System Variable (s):

Set the Catalina_Home environment variable:

Click - New, enter in the variable name: Catalina_home

Enter: D: / Tomcat in variable values

Then - determined that the Catalina_Home environment variable has been set.

Set the Catalina_Base environment variable:

Click --- New, type in the variable name: Catalina_Base

Enter: D: / Tomcat in variable values

Then - determined that the Catalina_Base environment variable is set. Then modify the ClassPath in the environment variable, add servlet.jar under CommON / lib under the Tomat installation directory to ClassPath,

The modified ClassPath is as follows:

ClassPath = D: / java / bin;; D: / java / lib; d: /java/lib/dt.jar; d: /java/lib/tools.jar; d: / tomcat / common / lib / servlet .jar

You can then start Tomcat, access http: // localhost: 8080 in IE, if you see the Tomcat's welcome page, the installation is successful.

If the Tomcat is installed in the top, continue to install the JSP to access the SQL Server 2000 driver:

Step 3: ---- Install JSP Access SQL Server 2000 driver:

Download drivers from Microsoft's website: SQL Server 2000 For JDBC driver, in Google, you can search in Google.

Then install it. (For example, the installation directory is d: / sqldriverforjdbc.)

Then you must use the three JAR files in the LIB directory in the installation directory:

Msbase.jar, mssqlserver.jar, msutil.jar Copy to the Tomcat directory under the common / lib directory, then,

Modify the ClassPath in the environment variable,

Put the SQL Server 2000 for JDBC driver installation directory

D: /sqldriverforjdbc/lib/msbase.jar; d: /sqldriverforjdbc/lib/mssqlserver.jar; d: /sqldriverforjdbc/msutil.jar

Add to ClassPath,

The modified ClassPath is as follows:

ClassPath = D: / java / bin;; d: / java / lib; d: /java/lib/dt.jar; d: /java/lib/tools.jar; d: / lubeetomcat / common / lib / servlet .jar; d: /sqldriverforjdbc/lib/msbase.jar; d: /sqldriverforjdbc/lib/msqlser.jar; d: /sqldriverforjdbc/msutil.jar

Must restart Tomcat!

The purpose of this is that the JSP page does not have a problem that the SQL Server Driver class library does not appear during the compilation process.

Write a simple JSP code to test the connection SQL Server 2000

<% @ Page import = "java.lang. *, Java.io. *, java.sql. *, Java.util. *" Contenttype = "text / html; charSet = GB2312"%>

<% Class.Forname ("com.microsoft.jdbc.sqlser.sqlserverdriver). Newinstance ();

String Url = "JDBC: Microsoft: SQLServer: // localhost: 1433; DatabaseName = PUBS";

// Pubs for your database

String User = "sa";

String password = "admin";

Connection conn = drivermanager.getConnection (URL, User, Password); statement stmt = conn.createstatement (ResultSet.Type_Scroll_Sensitive, ResultSet.concur_updata);

String SQL = "SELECT JOB_ID, JOB_DESC from JOBS";

ResultSet RS = Stmt.executeQuery (SQL);

While (rs.next ()) {%>

Your first field content is: <% = rs.getstring (1)%>

Your second field content is: <% = rs.getstring (2)%>

<%}%>

<% Out.print ("Database Success, Congratulations");%>

<% Rs.close ();

Stmt.close ();

CONN.CLOSE ();

%>

Save the above JSP code as SQL_TEST.JSP, put it under the / root directory.

Enter: http:// localhost: 8080 / sql_test.jsp, if all configured success, will be displayed:

Your first field content is: 1

Your second field content is: New Hire - Job Not Specified

Your first field content is: 2

Your second field content is: Chief Executive Offer

Your first field content is: 3

Your second field content is: Business Operations Manager

Your first field content is: 4

Your second field content is: Chief Financial OffiCier

Your first field content is: 5

Your second field content is: Publisher

Your first field content is: 6

Your second field content is: Managing Editor

Your first field content is: 7

Your second field content is: Marketing Manager

Your first field content is: 8

Your second field content is: Public Relations Manager

Your first field content is: 9

Your second field content is: Acquisitions Manager

Your first field content is: 10

Your second field content is: Productions Manager

Your first field content is: 11

Your second field content is: Operations Manager

Your first field content is: 12

Your second field content is: editor

Your first field content is: 13

Your second field content is: Sales Repesentative

Your first field content is: 14

Your second field content is: Designer

Database operation is successful, congratulations

All content involved in all the above contents:

Operating system: Window 2000 Server

J2SDK version: J2SDK-1_4_2_04-windows

Tomcat version: Jakarta-Tomcat-4.1.30

Local Database: SQL Server 2000

转载请注明原文地址:https://www.9cbs.com/read-122871.html

New Post(0)