130 likes | 309 Views
在 FreeBSD 中打造 JSP 環境與 java application 的概念. JDK1.4+Tomcat J2 sdk. FreeBSD Ports: Java. jdk-1.4.2p6_4 http://www.freebsd.org/cgi/cvsweb.cgi/ports/java/jdk14/jdk14.tar.gz?tarball=1
E N D
在FreeBSD中打造JSP環境與java application的概念 JDK1.4+Tomcat J2 sdk
FreeBSD Ports: Java • jdk-1.4.2p6_4 • http://www.freebsd.org/cgi/cvsweb.cgi/ports/java/jdk14/jdk14.tar.gz?tarball=1 • Requires:XFree86-libraries-4.3.0_7, expat-1.95.7, fontconfig-2.2.3,1, freetype2-2.1.7_3, gettext-0.13.1_1, gmake-3.80_2, imake-4.3.0_2, javavmwrapper-1.5, libiconv-1.9.2, linux-sun-jdk-1.4.2.05, linux_base-7.1_7, m4-1.4_1, nspr-4.4.1_1, open-motif-2.2.2_2, perl-5.8.4, pkgconfig-0.15.0_1, urwfonts-1.0, zip-2.3_1 • Cp –R distfiles /usr/ports/
JDK1.4安裝程序(1/2): • 1. 安裝 ports/java/linux-sun-jdk14 • # cd /usr/ports/linux-sun-jdk14 • # make install • 2. 手動設定 linux-sun-jdk14 的執行環境 • 在 /etc/fstab 中加入 linprocfs /compat/linux/proc linprocfs rw 0 0 • root 執行# kldload linprocfs # mount /compat/linux/proc
JDK1.4安裝程序(2/2): • 3. 安裝 ports/java/jdk14 • # cd /usr/ports/java/jdk14 • #make install • 4.後續設定 • 在 /etc/rc.conf 中加入linux_enable="YES"
tomcat安裝程序:binary • binary • http://apache.cdpa.nsysu.edu.tw/jakarta/tomcat-5/v5.0.27/bin/jakarta-tomcat-5.0.27.tar.gz • # tar xvfz jakarta-tomcat-5.0.27.tar.gz • #mv jakarta-tomcat-5.0.27 tomcat
環境變數的設定 • 在root的bash設定檔.profile中加入 • JAVA_HOME=/usr/local/jdk1.4.2/ • PATH=/usr/local/jdk1.4.2/bin/:$PATH • CLASSPATH=/usr/local/share/java/classes/:/usr/local/jdk1.4.2/lib/:/usr/local/jdk1.4.2/tools.jar • export JAVA_HOME PATH CLASSPATH • CATALINA_HOME=/usr/local/jakarta-tomcat5.0/ • TOMCAT_HOME=/usr/local/jakarta-tomcat5.0/ • PATH=/usr/local/jakarta-tomcat5.0/bin:$PATH
Tomcat啟動程序: • 設定sysctl -w net.inet6.ip6.v6only=0或在/etc/sysctl.conf加入net.inet6.ip6.v6only=0於開機時自動關閉net.inet6.ip6 • # /usr/local/tomcat/bin/startup.sh • 連線測試http://163.27.230.40:8080
Jsp範例(1/2)index.html • <html> • <head> • <title>輸入資料的表單</title> • </head> • <body> • <form action=echo.jsp method=post> • <table border=0> • <tr><td>姓名:</td> • <td><input type=text size=20 name=name></td> • </tr> • <tr><td>興趣:</td> • <td><input type=text size=20 name=hobby></td> • </tr> • <tr><td><input type=submit value=送出></td> • <td><input type=reset value=重寫></td> • </tr> • </table> • </form> • </body> • </html>
Jsp範例(2/2) echo.jsp • <html> • <title>輸入資料</title> • <body> • <% • String name = request.getParameter("name"); • String hobby = request.getParameter("hobby"); • out.print( name + ",你喜歡" + hobby + "。"); • %> • </body> • </html>
Java(TM) 2 SDK, Standard Edition 1.4.2_05 • 下載網址https://sdlcweb1b.sun.com/ECom/EComActionServlet/LegalPage:~:com.sun.sunit.sdlc.content.LegalWebPageInfo;jsessionid=sdlcweb1b.sun.com-74c3%3A41125fbb%3A9b547aa38b773531 • For windows版本下載 http://192.18.97.45/ECom/EComTicketServlet/BEGINsdlcweb1b.sun.com-74c3%3A41125fbb%3A9b547aa38b773531/-2147483648/472144287/1/489890/489662/472144287/2ts+/westCoastFSEND/j2sdk-1.4.2_05-oth-JPR/j2sdk-1.4.2_05-oth-JPR:2/j2sdk-1_4_2_05-windows-i586-p.exe
Java Application環境設定(1/2) • 控制台->系統->進階->環境變數->新增 • 變數名稱 CLASSPATH • 變數值D:\j2sdk1.4.0.03;D:\j2sdk1.4.0.03\mysql-connector-java-3.0.11-stable;.;
Java Application環境設定(2/2) • 控制台->系統->進階->環境變數 • 變數名稱 path • 變數值 • D:\j2sdk1.4.0.03\bin
Java application範例 • import java.awt.*; • import java.awt.event.*; • public class HelloWorldFrame extends java.awt.Frame { • public static void main(String args[]){ • new HelloWorldFrame(); • } • // 建構函式 • public HelloWorldFrame() { • super("Hello World"); • this.setSize(200, 200); • this.show(); • this.addWindowListener(new WindowAdapter() { • public void windowClosing(WindowEvent e) { • System.exit(0); • } • }); • } • public void paint(Graphics g) { • g.drawString("Hello World Frame", 50, 50); • } • }