1. 安裝jdk
sudo apt-get install openjdk-6-jdk
2. 安裝apache2
sudo apt-get install apache2
3. 安裝mysql
(1) 安裝
sudo apt-get install mysql-sql
(2)創(chuàng)建數(shù)據(jù)庫(kù)和表
mysql -uroot -p
4. 安裝tomcat
(1)安裝
在http://tomcat.apache.org/download-60.cgi頁(yè)面中下載Core里的tar.gz文件;下載完解壓后,將解壓后的文件夾移至/usr/local中。
(2)啟動(dòng)tomcat
在終端執(zhí)行/usr/local/apache-tomcat-6.0.35/bin/startup.sh
5. 在jsp中使用JDBC來(lái)連接MySQL數(shù)據(jù)庫(kù)
(1)下載JDBC驅(qū)動(dòng)程序
www.mysql.com/downloads/中尋找connectors, 然后網(wǎng)頁(yè)左側(cè)有connector/J 點(diǎn)擊會(huì)出現(xiàn)供選擇的tar.gz和zip文件下載(下載.tar.gz文件 ),下載完畢后解壓縮。
(2)配置連接文件
將剛剛展開的mysql-connector-java-5.1.18 中的mysql-connector-java-5.1.18-bin.jar文件拷貝到上面安裝的jdk 和 tomcat下的lib文件夾中:
jdk:/usr/lib/jvm/java-6-openjdk/lib
tomcat:/usr/local/apache-tomcat-6.0.35/lib/
6. 測(cè)試文件
(1)創(chuàng)建test站點(diǎn)
創(chuàng)建目錄:/usr/local/apache-tomcat-6.0.35/lib/apache-tomcat-6.0.35/webapps/test
將/usr/local/apache-tomcat-6.0.35/lib/apache-tomcat-6.0.35/webapps/Root/WEB-INF目錄拷貝到/usr/local/apache-tomcat-6.0.35/lib/apache-tomcat-6.0.35/webapps/test中。
(2)創(chuàng)建test文件
創(chuàng)建文件:/usr/local/apache-tomcat-6.0.35/lib/apache-tomcat-6.0.35/webapps/test/test.jsp
<%@ page contentType="text/html; charset=gb2312" import="java.util.*" %>
<%@ page import="java.sql.*"%>
jsp1
<% out.print("helloworld"); %>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/kpi_android_cn","root","1234");
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
String sql = "select * from LaunchSpeed";
ResultSet rs = stmt.executeQuery(sql); %>
<% while(rs.next()){out.println(rs.getString(5)) ;}%>
<%out.print("ok");%>
7. 查看結(jié)果:
在瀏覽器地址欄輸入:localhost:8080/test/test.jsp,查看網(wǎng)頁(yè)是否顯示對(duì)應(yīng)數(shù)據(jù)庫(kù)中的數(shù)據(jù)。