在Linux下配置JSP+TOMCAT+MySQL環境
1 下載安裝文件
1) jdk-1_2_2_017-Linux-i586.tar.gz
下載地址http://Java.sun.com/products/archive/J2SE/1.2.2_017/
2) jakarta-tomcat-4.1.31.tar.gz
下載地址http://apache.freelamp.com/jakarta/tomcat-4/v4.1.31/bin/jakarta-tomcat-4.1.31.tar.gz
3) MySQL-connector-Java-3.1.6.tar.gz
下載地址http://dev.MySQL.com/downloads/connector/j/3.1.Html
2 用root身份安裝jdk,tomcat,MySQL驅動
1) 拷貝安裝文件到/usr/local/目錄
cp /root/src/jdk-1_2_2_017-Linux-i586.tar.gz /usr/local/
cp /root/src/tar -zxvf ./jakarta-tomcat-4.1.31.tar.gz /usr/local/
cp /root/src/tar -zxvf ./MySQL-connector-Java-3.1.6.tar.gz /usr/local/
2) 解包
cd /usr/local
tar -zxvf ./jdk-1_2_2_017-Linux-i586.tar.gz
tar -zxvf ./jakarta-tomcat-4.1.31.tar.gz
tar -zxvf ./MySQL-connector-Java-3.1.6.tar.gz
3) 刪除原安裝文件
rm -f ./*.tar.gz
4) 拷貝MySQL驅動
cp ./mysql-connector-java-3.1.6/MySQL-connector-Java-3.1.6-bin.jar ./jakarta-tomcat-4.1.31/webaPPS/ROOT/WEB-INF/lib/
3 配置JDK環境變量
修改/etc/profile,加入如下幾行
Java_HOME=/usr/local/jdk1.2.2
JRE=/usr/local/jdk1.2.2/jre
CLASSPATH=$JAVA_HOME/lib:$JRE/lib:/usr/local/jakarta-tomcat-4.1.31/webaPPS/ROOT/WEB-INF/lib/MySQL-connector-Java-3.1.6-bin.jar:.
PATH=$PATH:$Java_HOME/bin:$JRE/bin:.
export Java_HOME JRE CLASSPATH
export PATH
4 啟動TOMCAT
/usr/local/jakarta-tomcat-4.1.31/bin/startup.sh
5 關閉TOMCAT
/usr/local/jakarta-tomcat-4.1.31/bin/shutdown.sh
6 寫MySQL.JSP 測試
<%@ page contentType="text/Html;charset=gb2312"%>
<%@ page import="Java.sql.*"%>
<Html>
<body>
<%Class.forName("org.gjt.mm.MySQL.Driver").newInstance();
String url ="jdbc:MySQL://localhost/phpbb?user=phpbb&passWord=PHPbb&useUnicode=true&characterEncoding=8859_1";
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="show tables";
ResultSet rs=stmt.executeQuery(sql);%>
<%while(rs.next()) {%>
<%=rs.getString(1)%>
<br>
<%}%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</Html>
7 外部測試地址http://210.51.1.148:8080/JSp/MySQL.JSP