{{{ #!html

JSP 筆記

}}} [[PageOutline]] = 一、安裝 = == 1.1 安裝 == * 注意: 大部分的使用者都不建議用apt-get 安裝tomcat 因此建議用tarball方式解壓縮 * 下載: [http://ftp.twaren.net/Unix/Web/apache/tomcat/tomcat-6/v6.0.20/bin/apache-tomcat-6.0.20.tar.gz tomcat 6.0.20 2009/08/06] * 安裝: {{{ sudo mv ~/Desktop/apache-tomcat-6*.gz /opt/ cd /opt sudo tar -zxvf apache-tomcat-6*.gz sudo mv apache-tomcat-6* tomcat sudo chown -R `whoami`:`whoami` tomcat }}} == 1.2 bootstrap == 若要系統開機就載入tomcat {{{ cd /opt/tomcat/bin tar xvfz jsvc.tar.gz cd jsvc-src autoconf ./configure make cp jsvc .. cd /opt/tomcat/ ./bin/jsvc -cp ./bin/bootstrap.jar -outfile ./logs/catalina.out -errfile ./logs/catalina.err org.apache.catalina.startup.Bootstrap }}} == 1.3 啟動停止tomcat == 建立 /etc/init.d/tomcat ,內容為: {{{ #!text #! /bin/sh PATH=$PATH:/opt/tomcat/bin do_start () { /opt/tomcat/bin/startup.sh } do_stop () { /opt/tomcat/bin/shutdown.sh } case "$1" in start) do_start ;; restart|reload|force-reload) do_stop do_start ;; stop) do_stop ;; *) echo "Usage: $0 start|stop" >&2 exit 3 ;; esac }}} * 使用方法: * 開啟 /etc/init.d/tomcat start * 關閉 /etc/init.d/tomcat stop = 二、 Hello World = == 2.1 撰寫 hello.jsp == {{{ cd /opt/tomcat/webapps/ROOT/ mkdir test cd test touch hello.jsp chmod 755 hello.jsp }}} hello.jsp 的內容為 {{{ #!text Hello World <% String s = "Eric"; %>

Hello <%=s%>

}}} {{{ /etc/init.d/tomcat restart }}} * 瀏覽: [[http:localhost:8080/test/hello.jsp ]]