、整合Apache+Tomcat服务器
1.复制mod_jk_1.2.5_2.0.47.dll文件到C://Apache2//modules目录
2.Apache配置:
C://apahce2//conf//httpd.conf
httpd.conf
在此配置文件最后添加以下语句用以支持jsp:
LoadModulejk_modulemodules/mod_jk_1.2.5_2.0.47.dll
JkWorkersFile/"C:/Tomcat5.0/conf/workers.properties/"
JkMount/servlet/*ajp13
JkMount/*.jspajp13
3.查看C://Tomcat5.0//conf//server.xml文件中有关端口“8009”是否被注释如果是和我这版本致话不用修改
4.在C://Tomcat5.0//conf//目录下新建文件名为“workers.properties”文件将如下内容复制到新建文件
workers.properties中
workers.properties
#只复制以下内容即可:
#这现行根据安装目录做修改
workers.tomcat_home=C://Tomcat5.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._path=$(workers.tomcat_home)$(ps)es
worker.inprocess._path=$(workers.tomcat_home)$(ps)lib$(ps)jaxp.jar
worker.inprocess._path=$(workers.tomcat_home)$(ps)lib$(ps)parser.jar
worker.inprocess._path=$(workers.tomcat_home)$(ps)common$(ps)lib$(ps)jasper.jar
worker.inprocess._path=$(workers.tomcat_home)$(ps)common$(ps)lib$(ps)servlet.jar
worker.inprocess._path=$(workers.tomcat_home)$(ps)common$(ps)lib$(ps)webserver.jar
worker.inprocess._path=$(workers.java_home)$(ps)lib$(ps)tools.jar
worker.inprocess.cmd_line=-config
worker.inprocess.cmd_line=$(workers.tomcat_home)/conf/jni_server.xml
worker.inprocess.cmd_line=-home
worker.inprocess.cmd_line=$(workers.tomcat_home)
worker.inprocess.jvm_lib=$(workers.java_home)$(ps)jre$(ps)bin$(ps)ic$(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.到此Apache和Tomcat整合完成重启Apache和Tomcat服务器 [Page]
用编辑器编写如下内容:
<%@pagecontentType=/"text/html;char=gb2312/"%>
<html>
<head>
<title>HI-JSP实验</title>
</head>
<body>
<%
StringMsg=/"ThisisJSPtest!看到这段话恭喜你成功了!/";
out.pr(/"HelloWorld!/");
%>
<h3><%=Msg%></h3>
Thecurrentdateandtimeis<%=java.util.Date%>
<br>
<%
Stringstr=/"Usingtrimandsubcanbeveryuseful/";
out.prln(str);
%>
</body>
</html>
保存文件名为“test.jsp”到C://Tomcat5.0//webapps//ROOT目录然后打开浏览器浏览
:http://localhost:8080/test.jsp如果显示正常然后将地址改为:http://localhost/test.jsp显示正常介绍说明配置
成功严格按以上介绍说明安装配置都会次成功
如果想更改tomcat文档路径<Host>字段中增加
<Contextpath=/"/"docBase=/"D://www/"debug=/"0/"reloadable=/"true/"crossContext=/"true/"/>
1 2、整合Apache+Tomcat+MySQL
这步相对简单许多但也是最不容易成功部分前面已经将JSPMySQL驱动放到相应目录中环境变量也设置所以只
是测试JSP是否可以连接MySQL数据库
1.测试1用编辑器编写如下内容:
<%@pagecontentType=/"text/html;char=gb2312/"%>
<%
java.sql.Connectionconn;
java.lang.StringstrConn;
Class.forName(/"org.gjt.mm.mysql.Driver/").Instance;
conn=java.sql.DriverManager.getConnection(/"jdbc:mysql://localhost/test/",/"root/",/"/");
%>
注:数据库此处为:test连接数据库存用户名为:root密码为空根据自己数据库作相应修改
保存文件名为“test-mysql.jsp”到C://Tomcat5.0//webapps//ROOT目录然后打开浏览器浏览
:http://localhost:8080/test-mysql.jsp或http://localhost/test-mysql.jsp运行后如果显示为空白页面介绍说
明连接数据库成功否则介绍说明没有连接成功请往回逐步仔细配置
2.测试2用编辑器编写如下内容:
<%@pagecontentType=/"text/html;char=GBK/"%>
<%@pagelanguage=/"java/"import=/"java.sql.*/"%>
<%
Connectionconn=null;
Class.forName(/"org.gjt.mm.mysql.Driver/").Instance; [Page]
conn=java.sql.DriverManager.getConnection(/"jdbc:mysql://localhost/test/",/"root/",/"/");
(connnull){
.out.prln(/"getConnError/");
}
Statementstmt=conn.createStatement;
ResultSetRS_result=null;
%>
<html>
<head>
<title>测试</title></head>
<body>
<%
RS_result=stmt.executeQuery(/"select*fromguestbook/");
StringName;
while(RS_result.next)
{
Name=RS_result.getString(/"name/");
%>
<%=Name%>
<%
}
RS_result.close;
stmt.close;
conn.close;
%>
</body>
</html>
保存文件名为“test-mysql2.jsp”到C://Tomcat5.0//webapps//ROOT目录然后打开浏览器浏览
:http://localhost:8080/test-mysql2.jsp或http://localhost/test-mysql2.jsp运行后