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

xiaoxiao2021-03-06  62

Step 1: ---- Install J2SDK:

To the Sun Official Site (http://java.sun.com) Download J2SDK installation file: J2SDK-1_4_2_04-windows-i586-p.exe, after downloading J2SDK; after installation, set environment variables: My computer --- Property --- Advanced - Environment Variables; Select - System Variables (S): Set Java_Home Environment Variables: Click - New, Enter: Java_home Enter: D in Variables: D : / Java (assuming J2SDK installation Under the directory D: / Java, anyway is the J2SDK installation directory.) Then - determined, the Java_Home environment variable is set. Set the ClassPath environment variable: click - New, enter in the variable name: ClassPath Enter: D: / java / lib; d: / java / lib / dt. JAR; D: /JAVA/LIB/Tools.jar (middle point "." and semicolon ";") Then --- Determine, the ClassPath environment variable is set. Set the PAT environment variable: click - New, type in the variable name: Path Enter: D: / java; .; D: / Java / bin (middle point "." And Sizted " "" It is essential.) Then --- OK, the Java_Home environment variable has been set. After the three environment variables are set, write a simple Java program to test whether J2SDK has been installed successfully: Newly built a directory TEST in D: / Next: 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 command javac test.java java test. If you see the printed this is a test program. If you have successful installation, if you don't print this sentence If 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:

Download Tomcat: Jakarta-Tomcat-4.1.30.exe after downloading Tomcat: Jakarta-Tomcat-4.1.30.exe, after downloading. (,, : Click - New, enter in the variable name: Catalina_home Enter: d: / tomcat in the variable value, then determine, the Catalina_Home environment variable is set. Set the Catalina_Base environment variable: Click - New, Enter: Catalina_base Enter: Catalina_base Enter: D: / Tomcat and --- OK, you have set a CataLina_Base environment variable. Then modify the ClassPath in the environment variable, append the servlet.jar under the Tomat installation directory to the 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 can then start Tomcat, access http: // localhost in IE : 8080, if you see the Tomcat's welcome page, the instructions are successful.

If the Tomcat is installed successfully, continue to install the JSP to access the JSP to access the SQL Server 2000 driver: Step 3: ---- Install JSP Drivers to Access SQL Server 2000: Download Drivers from Microsoft Site: SQL Server 2000 for JDBC driver, in Google is casually searching. Then install it. (For example, the installation directory is d: / sqldriverforjdbc.) Then you must copy the three JAR files in the installation directory: msbase.jar, mssqlser.jar, msutil.jar Copy to the Tomcat directory in the common / lib directory, then Modify the ClassPath in the environment variable, put the D: /SQLDRIVERFORJDBC/LIB /SQLDRIVERFORJDBC/LIB/msqldriver.jar; d: /sqldriverforjdbc/lib/mssqlserforjdbc/msu /sqldriverforjdbc/msutil.jar appended Going to classpath, the modified ClassPath is as follows: ClassPath = D: / java / bin;; d: / java / lib; d: /java/lib/tt.jar; d: /java/lib/tools.jar ; D: /lubeetomcat/common/lib/servlet.jar; d: /sqldriverforjdbc/lib/msbase.jar; d: /sqldriverforjdbc/lib/msqlserver.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 for testing 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_UPDATABLE); String sql = "select job_id, job_desc from jobs"; ResultSet rs = stmt.executeQuery (sql); while (rs.next ()) {%> your first field content To: <% = rs.getstring (1)%>
Your second field content is: <% = rs.getstring (2)%>
<%}%> <% out.print "Database operation, congratulations");%> <% rs.close (); stmt.close (); conn.close ();%> Save the above JSP code as SQL_TEST.JSP, put it under the / root directory.

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

New Post(0)