Integrate Apache + Tomcat + MySQL_MySQL

Source: Internet
Author: User
Integrate Apache + Tomcat + MySQL ApacheTomcat

1. integrate Apache + Tomcat servers

1. copy the mod_jk_1.2.5_2.0.47.dll file to the C:/Apache2/modules Directory.
2. Apache configuration:
C:/apahce2/conf/httpd. conf
Httpd. conf
Add the following statement at the end of the configuration file to support jsp programs:
LoadModule jk_module modules/mod_jk_1.2.5_2.0.47.dll

JkWorkersFile "C:/Tomcat 5.0/conf/workers. properties"
JkMount/servlet/* ajp13
JkMount/*. jsp ajp13

3. check whether the port "5.0" in the C:/Tomcat 8009/conf/server. xml file is commented out. if it is the same as my version, do not modify it.
4. in the C:/Tomcat 5.0/conf/directory, create a file named "workers. properties" and copy the following content to the workers. properties file.

Workers. properties
# Simply copy the following content:

# Modify the current directory according to the installation directory
Workers. tomcat_home = C:/Tomcat 5.0
Workers. java_home = C:/j2sdk1.4.1 _ 01
Ps =/
# Worker. list = ajp13
Worker. list = ajp12, ajp13

Worker. ajp12.port = 8007
Worker. ajp12.host = localhost
Worker. ajp12.type = ajp12
Worker. ajp12.lbfactor = 1

Worker. ajp13.port = 8009
Worker. ajp13.host = localhost
Worker. ajp13.type = ajp13
Worker. ajp13.lbfactor = 1

Worker. loadbalancer. type = lb

Worker. loadbalancer. balanced_workers = ajp12, ajp13
Worker. inprocess. type = jni
Worker. inprocess. class_path = $ (workers. tomcat_home) $ (ps) classes
Worker. inprocess. class_path = $ (workers. tomcat_home) $ (ps) lib $ (ps) jaxp. jar

Worker. inprocess. class_path = $ (workers. tomcat_home) $ (ps) lib $ (ps) parser. jar

Worker. inprocess. class_path = $ (workers. tomcat_home) $ (ps) common $ (ps) lib $ (ps) jasper. jar

Worker. inprocess. class_path = $ (workers. tomcat_home) $ (ps) common $ (ps) lib $ (ps) servlet. jar

Worker. inprocess. class_path = $ (workers. tomcat_home) $ (ps) common $ (ps) lib $ (ps) webserver. jar

Worker. inprocess. class_path = $ (workers. java_home) $ (ps) lib $ (ps) tools. jar

Worker. inprocess. worker _line =-config

Worker. inprocess. worker _line = $ (workers. worker at_home)/conf/jni_server.xml

Worker. inprocess. worker _line =-home

Worker. inprocess. worker _line = $ (workers. worker at_home)

Worker. inprocess. jvm_lib = $ (workers. java_home) $ (ps) jre $ (ps) bin $ (ps) classic $ (ps) jvm. dll


Worker. inprocess. stdout = $ (workers. tomcat_home) $ (ps) inprocess. stdout

Worker. inprocess. stderr = $ (workers. tomcat_home) $ (ps) inprocess. stderr

Worker. inprocess. sysprops = tomcat. home =$ (workers. tomcat_home)


5. now Apache and Tomcat are integrated. restart the Apache and Tomcat servers,
Write the following content in the editor:

<% @ Page contentType = "text/html; charset = gb2312" %>



HI-JSP experiment


<%
String Msg = "This is JSP test! Congratulations! ";
Out. print ("Hello World! ");
%>
<% = Msg %>
The current date and time is <% = new java. util. Date () %>


<%
String str = "Using trim () and substring () can be very useful ";
Out. println (str );
%>

Save the file name as "test. jsp "to the C:/Tomcat 5.0/webapps/ROOT directory, then open the browser, browse: http: // localhost: 8080/test. jsp. if the display is normal, change the address to http: // localhost/test. if jsp is displayed as normal, the configuration is successful. The installation and configuration will be successful once according to the preceding instructions.

If you want to change the tomcat document path, Add in field

2. integrate Apache + Tomcat + MySQL

This step is relatively simple, but it is also the most difficult part to succeed. the MySQL driver of JSP has been put in the corresponding directory, and the environment variables are also set, therefore, we only test whether JSP can connect to the MySQL database.
1. test 1. write the following content in the editor:

<% @ Page contentType = "text/html; charset = gb2312" %>
<%
Java. SQL. Connection conn;
Java. lang. String strConn;
Class. forName ("org. gjt. mm. mysql. Driver"). newInstance ();
Conn = java. SQL. DriverManager. getConnection ("jdbc: mysql: // localhost/test", "root ","");
%>
Note: Here the database is: the user name for connecting to the data inventory with test is: the root password is blank. Modify your database accordingly.

Save the file name as test-mysql.jsp to the C:/Tomcat 5.0/webapps/ROOT directory, then open your browser, browse: http: // localhost: 8080/test-mysql.jsp or http: // localhost/test-mysql.jsp, after running, if displayed as a blank page, it indicates that the database is connected successfully, otherwise it indicates that no connection is successful, please step back carefully configured.

2. test 2. Compile the following content in the editor:

<% @ Page contentType = "text/html; charset = GBK" %>
<% @ Page language = "java" import = "java. SQL. *" %>
<%
Connection conn = null;
Class. forName ("org. gjt. mm. mysql. Driver"). newInstance ();
Conn = java. SQL. DriverManager. getConnection ("jdbc: mysql: // localhost/test", "root ","");
If (conn = null ){
System. out. println ("get Conn Error ");
}
Statement stmt = conn. createStatement ();
ResultSet RS_result = null;
%>


Test

<%
RS_result=stmt.exe cuteQuery ("select * from guestbook ");
String Name;
While (RS_result.next ())
{
Name = RS_result.getString ("name ");
%>
<% = Name %>
<%
}
RS_result.close ();
Stmt. close ();
Conn. close ();
%>

Save the file name as test-mysql2.jsp to the C:/Tomcat 5.0/webapps/ROOT directory, then open your browser, browse: http: // localhost: 8080/test-mysql2.jsp or http: // localhost/test-mysql2.jsp

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.