在 FreeBSD 中打造 JSP 環 境與 java application 的 概念 JDK1.4+Tomcat J2 sdk
FreeBSD Ports: Java jdk-1.4.2p6_4 jdk-1.4.2p6_4 ava/jdk14/jdk14.tar.gz?tarball=1 ava/jdk14/jdk14.tar.gz?tarball=1 ava/jdk14/jdk14.tar.gz?tarball=1 Requires: XFree86-libraries-4.3.0_7, expat , fontconfig-2.2.3,1, freetype _3, gettext _1, gmake-3.80_2, imake _2, javavmwrapper-1.5, libiconv-1.9.2, linux-sun-jdk , 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 _1, urwfonts-1.0, zip-2.3_1 XFree86-libraries-4.3.0_7expat fontconfig-2.2.3,1freetype _3 gettext _1gmake-3.80_2imake _2javavmwrapper-1.5libiconv linux-sun-jdk linux_base-7.1_7 m4-1.4_1nspr-4.4.1_1open-motif-2.2.2_2 perl-5.8.4pkgconfig _1urwfonts-1.0 zip-2.3_1XFree86-libraries-4.3.0_7expat fontconfig-2.2.3,1freetype _3 gettext _1gmake-3.80_2imake _2javavmwrapper-1.5libiconv linux-sun-jdk linux_base-7.1_7 m4-1.4_1nspr-4.4.1_1open-motif-2.2.2_2 perl-5.8.4pkgconfig _1urwfonts-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 linprocfs /compat/linux/proc linprocfs rw 0 0 root 執行 # kldload linprocfs # mount /compat/linux/proc # 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 cat-5/v5.0.27/bin/jakarta-tomcat tar.gz cat-5/v5.0.27/bin/jakarta-tomcat tar.gz cat-5/v5.0.27/bin/jakarta-tomcat tar.gz # tar xvfz jakarta-tomcat tar.gz #mv jakarta-tomcat 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/loc al/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 連線測試
Jsp 範例 (1/2)index.html 輸入資料的表單 輸入資料的表單 姓名: 姓名: 興趣: 興趣:
Jsp 範例 (2/2) echo.jsp 輸入資料 輸入資料 <% String name = request.getParameter("name"); String hobby = request.getParameter("hobby"); out.print( name + " ,你喜歡 " + hobby + " 。 "); %>
Java(TM) 2 SDK, Standard Edition 1.4.2_05 下載網址 LegalPage:~:com.sun.sunit.sdlc.content.LegalWebPag eInfo;jsessionid=sdlcweb1b.sun.com- 74c3%3A41125fbb%3A9b547aa38b LegalPage:~:com.sun.sunit.sdlc.content.LegalWebPag eInfo;jsessionid=sdlcweb1b.sun.com- 74c3%3A41125fbb%3A9b547aa38b LegalPage:~:com.sun.sunit.sdlc.content.LegalWebPag eInfo;jsessionid=sdlcweb1b.sun.com- 74c3%3A41125fbb%3A9b547aa38b For windows 版本下載 dlcweb1b.sun.com- 74c3%3A41125fbb%3A9b547aa38b773531/ / /1/489890/489662/ / 2ts+/westCoastFSEND/j2sdk-1.4.2_05-oth-JPR/j2sdk _05-oth-JPR:2/j2sdk-1_4_2_05-windows-i586- p.exe
Java Application 環境設定 (1/2) 控制台 -> 系統 -> 進階 -> 環境變數 -> 新增 變數名稱 CLASSPATH CLASSPATH 變數值 D:\j2sdk ;D:\j2sdk \mysql- connector-java stable;.;
Java Application 環境設定 (2/2) 控制台 -> 系統 -> 進階 -> 環境變數 變數名稱 path path 變數值 D:\j2sdk \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); }