A detailed explanation of the JSP's configuration under Windows and the connection to the SQL Server database

Source: Internet
Author: User
Tags filter connect sql server driver variables stmt variable web services oracle database
js|server|sqlserver|window| Data | database | Detailed recently in the learning JSP, about JSP running environment configuration problem really let me a lot of Kung Fu, environment configuration, connect SQL Sever 2000 database when a lot of problems, In view of this I have to configure the two aspects of their detailed steps to share with you, want to just contact JSP and determined in the JSP aspects of the achievements of the colleagues less to take some detours, let me make progress together. Have hope to communicate with me please add me qq:26544472 (please specify JSP communication in the verification information)

(i) About JSP configuration under Windows:

Sun's JSP (Java Server Pages) is a dynamic web development technology that executes on the server side, based on Java technology. When executing a JSP, you need to set up an engine that compiles JSP pages on the Web server. There are several ways to configure a JSP environment, but the main task is to install and configure the Web server and the JSP engine.

The following is the use of Tomcat as a JSP engine, with Tomcat, Apache, IIS three kinds of Web servers to tell the 3 kinds of building JSP operating environment scenarios.

Introduction of related Software

1, J2SDK:JAVA2 software development tools, is the basis of Java applications. JSP is based on Java technology, so you must install J2SDK before you configure the JSP environment.

2. Apache server: A common Web server developed by the Apache organization that provides Web services.

3, Tomcat server: Apache development of a JSP engine, itself has the function of a Web server, can be used as a stand-alone Web server. However, when Tomcat handles static HTML pages as a Web server, not as fast as Apache or as robust as Apache, we typically use Tomcat in conjunction with Apache so that Apache can service static page requests for the site, Tomcat, as a dedicated JSP engine, provides JSP parsing for better performance. And Tomcat itself is a subproject of Apache, so Tomcat provides strong support for Apache. For beginners, Tomcat is a good choice.

4, Mod_jk.dll:Apache organization Jakarta Project team developed to enable Apache support Tomcat Plug-ins. With this plugin, Tomcat is able to seamlessly connect to Apache.

5, Tc4ntiis.zip:Apache organization Jakarta Project team developed to enable IIS to support Tomcat Plug-ins.

Second, software download

1, J2SDK

Version: j2sdk1.4.1 (35.9MB)

Address: http://java.sun.com/j2se/1.4.1/download.html

2, Apache2

Version: Apache2.0.43 (6.69MB)

Address: http://www.apache.inetcosmos.org/dist/httpd/binaries/win32/

3, TOMCAT4

Version: 4.1.21 (8.33MB)

Address: http://jakarta.apache.org/builds/jakarta-tomcat-4.0/release/

4, Mod_jk.dll: (136KB)

Address: http://jakarta.apache.org/builds/jakarta-tomcat-connectors/jk/release/

5, Tc4ntiis.zip (220KB)

Address: Http://members.ozemail.com.au/~lampante/howto/tomcat/iisnt/tc4ntiis.zip

All of the above are free software.

III. Preparation before the configuration

(a) Prepare a test JSP page

Open a text editor such as Notepad, enter the following code, and save it as test. JSP (note that the extension is. jsp).

<HTML>
<HEAD>
<TITLE> JSP test Page </TITLE>
</HEAD>
<BODY>
<%out.println ("</BODY>
</HTML>

(ii) Installation of J2SDK

Regardless of the scenario, you must complete the installation of the J2SDK before installing and configuring the JSP engine.

1. Installation J2SDK

Under Windows, run the downloaded J2sdk-1_4_1_01-windows-i586.exe file directly, and install to a directory based on the installation wizard, such as installing to F:\J2SDK 1.4.1;

2. Add Environment variables

(1) If your operating system is win 98, you can edit Autoexec.bat directly with Notepad, add the following command line:

Path=%path%;f:\j2sdk1.4.1\bin
SET java_home=f:\j2sdk1.4.1
SET Classpath=f:\j2sdk1.4.1\lib\tools.jar

After saving, restart the computer so that the environment variables you add are valid.

(2) If your operating system is Win2000, configure the environment variables as follows. Right click on "My Computer", in the pop-up menu select "Properties" → "system features" → "Advanced" → "Environment variables", Pop-up Environment Variables dialog box, you can edit the system environment variables. Add path, Java_home, and classpath three variables with the same value as above.

Four, the JSP environment configuration scheme

(i) Programme I: J2sdk+tomcat

In this scenario, Tomcat is used as both a JSP engine and a Web server, and is relatively simple to configure.

1. Install Tomcat

Run the download directly jakarta-tomcat-4.0.1.exe, follow the usual Windows program installation steps to install the Tomcat, installed it will automatically find the location of the J2SDK. For example, install to F:\TOMCAT4.

2. Configure Tomcat Environment variables

Add a new environment variable tomcat_home, the variable value is F:\TOMCAT4, add method and J2SDK environment variable configuration method.

3. Test default Service

The Tomcat server can be run after Setup is complete. Start Tomcat with F:\tomcat4\bin\startup.exe and close with F:\tomcat4\bin\shutdown.exe. (if prompted out of the environment space error when executing startup.exe or Shutdown.exe, select "Properties" → "Memory" → "normal memory" in the menu of the DOS window, and modify the "initial environment" from "automatic" to "2816" It's OK. )

After you start Tomcat, open the browser, enter http://localhost:8080 in the Address bar (the Tomcat default port is 8080), and if you see the Tomcat welcome interface in the browser, the Tomcat is working properly.

4. Test Project

Put the test.jsp you just prepared in the f:\Tomcat\webapps\examples\jsp directory and enter http://localhost:8080/examples/jsp/test.jsp in the Address bar, if the browser displays "Hello world! , your JSP environment configuration is successful!

Because Tomcat itself has the functionality of a Web server, we don't have to install Apache, but it can also be integrated with Apache, as described below.

(ii) Programme II: J2SDK+APACHE+TOMCAT

Although Tomcat can also be used as a Web server, its handling of static HTML is not as fast as Apache, and its function as a Web server is far less than Apache, so integrate Apache and Tomcat, using Apache as a Web server, and Tomcat as a dedicated JSP engine. The configuration of this scenario is more complex, but it allows Apache and Tomcat to be perfectly integrated to achieve powerful functionality.

Note that because the IIS Web server uses port 80 by default, and Apache's default port is 80, if you are using the Win2000 operating system and the IIS is pre-installed, it is convenient to stop the IIS service before doing the following.

1. Install Apache

Run the downloaded Apache_2.0.43-win32-x86-no_ssl.exe, and follow the wizard to install to F:\Apache2. (Note that after the Apache2.0.43 installation is successful, you must rename the Index.html.en in the F:\Apache2\htdocs directory to index.html so that the Apache welcome interface is displayed normally when you test the default service).

2. Test Apache default Service

After the installation, the Apache server has been automatically run. Open the browser and enter in the Address bar: http://localhost (the Tomcat default port is 80), and if you see the Apache welcome interface in your browser, Apache works fine.

3, follow the steps of the program to install Tomcat, and ensure that it runs normally.

4. Copy the downloaded Mod_jk-2.0.42.dll to the F:\Apache2\modules directory.

5, the establishment of MOD_JK module work required working documents.

Open the Text editor and enter the following statement:

WORKERS.TOMCAT_HOME=F:\TOMCAT4 (Let the MOD_JK module know Tomcat)
workers.java_home=f:\j2sdk1.4.1 (Let mod_jk module know JSDK)
Ps=\
WORKER.LIST=AJP13 (mod_jk version of the module)
worker.ajp13.port=8009 (mod_jk port of work)
Worker.ajp13.host=localhost
Worker.ajp13.type=ajp13
Worker.ajp13.lbfactor=1

Save the above statement in the f:\Tomcat4\conf directory with the Workers.properties file name (Note: The file extension is. properties).

6, configure Apache.

Open f:\Apache2\conf\httpd.conf with a text editor

1 Find "DirectoryIndex", add index.jsp after Index.html.var;

2 at the end of httpd.conf, add the following code (in parentheses for explanation)

LoadModule Jk_module Modules/mod_jk-2.0.42.dll
(Load MOD_JK module, for handling Apache and Tomcat connections)
Jkworkersfile "F:/tomcat4/conf/workers.properties"
(Indicates the location of the working file Workers.properties required for MOD_JK module work)
jkmount/servlet/* ajp13
Jkmount/*.jsp ajp13
(Send all servlet and JSP requests through the AJP13 protocol to Tomcat to be processed by Tomcat)

3) to save after the completion of the addition.

7. Configure Tomcat

Open F:\Tomcat4\conf\server.xml with a text editor. Because TOMCAT4 does not enable AJP13 by default, the following code is found:

!--
<connector classname= "Org.apache.ajp.tomcat4.Ajp13Connector"
Port= "8009" minprocessors= "5" maxprocessors= "a" acceptcount= "ten" debug= "0"/>
-->

If you delete the annotation symbol!----, you can enable AJP13.

Then save, now Tomcat and Apache's consolidated configuration is basically complete.

8. Overall Test

Put the test.jsp in the f:\Tomcat\webapps\examples\jsp directory and start the APACHE2,TOMCAT4 in turn. Open the browser and enter http://localhost:8080/examples/jsp/test.jsp in the address bar, if "Hello world!" appears in the browser , then the Tomcat will work properly, and enter http://localhost/examples/jsp/test.jsp in the address bar if the http://localhost:8080/examples/jsp/ The results of test.jsp are the same, which means that Apache and Tomcat are integrated successfully!

(iii) Programme III: J2SDK+IIS+TOMCAT

The most common Web server under the Windows platform is undoubtedly IIS, and normally IIS does not support JSP, and we can enable IIS to send all JSP requests to Tomcat execution by using an IIS to the Tomcat redirection plug-in. You can make IIS more capable of processing jsps. If you are accustomed to using IIS, you can try this configuration. (If you have already installed the Apache server, please uninstall Apache for later operation.) )

1, follow the steps of the program to install Tomcat, and ensure that it runs normally. (e.g. installation to F:\TOMCAT4);

2, will download the Tc4ntiis.zip directly to the F:\TOMCAT4 directory. Review the files required by the configuration to ensure they are in the following locations:

F:\tomcat4\server\lib\ajp.jar
F:\tomcat4\server\lib\tomcat-util.jar F:\tomcat4\bin\native\isapi_redirect.dll f:\tomcat4\conf\ntiis\ Workers.properties f:\tomcat4\conf\ntiis\uriworkermap.properties F:\tomcat4\conf\ntiis\iis_redirect.reg
F:\tomcat4\log\iis_redirect.log

3. Open f:\tomcat4\conf\ntiis\workers.properties with a text editor, and modify the following values:

Workers.tomcat_home=f:\tomcat4
workers.java_home=f:\j2sdk1.4.1


4. Double-click F:\tomcat4\conf\ntiis\iis_redirect.reg to add the information in this registration file to the registry, but modify Log_file, Worker_file, Worker_mount_ File these three key values to suit your environment (such as Tomcat in this article is installed in F:\TOMCAT4 instead of the default C:\TOMCAT4). Add and modify the following figure after completion.

5, open Internet Services Manager, add a new virtual directory on the default site, name Jakarta, this virtual directory points to F:\tomcat4\bin\native, and start the default site.

6. Right-click the server name in Internet Services Manager, select Properties → the edit → ISAPI filter tab of the WWW service in the main property, add an ISAPI filter, named Jakarta Redirect, executable file specified as F:\ Tomcat4\bin\native\isapi_redirector.dll. After adding an ISAPI filter, the state of the Jakarta redirect is a red downward arrow that restarts the IIS service and becomes a green arrow.

7. Edit the Server.xml file and save it (the 7th step of the same scheme II).

8, restart IIS and Tomcat.

9, test project: Put the test.jsp in the f:\Tomcat\webapps\examples\jsp directory. Open the browser and enter http://localhost:8080/examples/jsp/test.jsp in the address bar, if "Hello world!" appears in the browser , then the Tomcat will work properly, and enter http://localhost/examples/jsp/test.jsp in the address bar if the http://localhost:8080/examples/jsp/ The results of the test.jsp are the same, which means that IIS and Tomcat consolidation are successful!

V. Concluding remarks

Build JSP operating environment is the basis of learning JSP technology, JSP engine a lot of types, configuration methods are also many, and the version of the software is constantly upgraded, we can according to their own needs and the actual situation to choose the appropriate configuration method. I hope this article gives some of the JSP environment Configuration scheme, for people who want to learn JSP help.



(ii) Detailed explanation of the connection to the SQL Server database:


The JDBC driver (Microsoft SQL Server Driver for JDBC) is first downloaded when you connect to the database, and after the installation (or possibly decompression) is Msbase.jar,mssqlserver.jar, Msutil.jar three jar files copied to tomcat under the Common/lib folder can be, this is necessary, the author therefore suffered a great blow, I hope you must first configure, otherwise your database is certainly not good; The following is a connection instance:
<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ page import= "java.sql.*"%>
<body>
<%class.forname ("Com.microsoft.jdbc.sqlserver.SQLServerDriver"). newinstance ();
String url= "Jdbc:microsoft:sqlserver://localhost:1433;databasename=pubs";
Pubs for your database of
String user= "SA";
String password= "";
Connection conn= drivermanager.getconnection (Url,user,password);
Statement stmt=conn.createstatement (resultset.type_scroll_sensitive,resultset.concur_updatable);
String sql= "SELECT * from Test";
ResultSet rs=stmt.executequery (SQL);
while (Rs.next ()) {%>
Your first field content is: <%=rs.getstring (1)%>
The contents of your second field are: <%=rs.getstring (2)%>
<%}%>
<%out.print ("Successful database operation, congratulations");%>
<%rs.close ();
Stmt.close ();
Conn.close ();
%>
</body>
Here I use the JSP operating environment is J2SDK + Tomcat + IIS, feel can also, mainly with the habit of IIS, we can according to their own interests and need to choose their own environmental development;
Finally, I would like to remind you that the JSP connection database used by the database is the most ideal database Oracle, so the server more mature readers can study the Oracle database connection, where the specific connection instance I no longer detailed description.


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.