{{{ #!html
jsp + servlet + javabean
教材1
}}} [[PageOutline]] = 一. 下載資源 = == 1.A 用 virtualbox 虛擬機器 == * [http://secuse.nchc.org.tw/jspservlet/u1004.vdi 下載 virtualbox 的硬碟檔] * 此硬碟檔為ubuntu 10.04 版本,已經調整好教材,請用virtualbox 3.2.2 以上版本掛載 == 1.B 自行下載資源 == 1. [http://secuse.nchc.org.tw/jspservlet/jspservlet%e5%88%9d%e9%9a%8e.pdf 下載 pdf 手冊][[BR]] 2. [http://secuse.nchc.org.tw/jspservlet/tomcat-6.0.26.tar.gz 下載tomcat 6.5] 3. [http://secuse.nchc.org.tw/jspservlet/eclipse-SDK-3.5.2-linux-gtk.tar.gz 下載 eclipse 3.5 linux版] = 二. 實做簡單的 servlet 範例 = * 已將tomcat 安裝於 /opt/tomcat/ 目錄下 == 2.1 == {{{ cd /opt/tomcat/webapps/ mkdir -p /opt/tomcat/webapps/FirstServlet/WEB-INF/classes mkdir /opt/tomcat/webapps/FirstServlet/WEB-INF/lib cd /opt/tomcat/webapps/FirstServlet/WEB-INF/classes gedit HelloServlet.java }}} {{{ #!java import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class HelloServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); String name = request.getParameter("name"); out.println(""); out.println(""); out.println("Hello Servlet"); out.println(""); out.println(""); out.println("

Hello! " + name + " !

"); out.println(""); out.println(""); out.close(); } } }}} {{{ cd /opt/tomcat/webapps/FirstServlet/WEB-INF/classes javac -classpath /opt/tomcat/lib/servlet-api.jar ./HelloServlet.java }}} {{{ #!xml HelloServlet HelloServlet HelloServlet /hello.do }}} {{{ cd /opt/tomcat bin/startup.sh }}} [http://localhost:8080/FirstServlet/hello.do?name=caterpillar] == 2.1 == == 2.1 == == 2.1 ==