Changes between Version 5 and Version 6 of waue/2010/0608
- Timestamp:
- Jun 8, 2010, 1:39:58 PM (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
waue/2010/0608
v5 v6 10 10 11 11 = 一. 下載資源 = 12 == 1.A 用 virtualbox 虛擬機器 == 13 * [http://secuse.nchc.org.tw/jspservlet/u1004.vdi 下載 virtualbox 的硬碟檔] 14 * 此硬碟檔為ubuntu 10.04 版本,已經調整好教材,請用virtualbox 3.2.2 以上版本掛載 12 == 1.A 用 virtualbox 虛擬機器 == 15 13 16 == 1.B 自行下載資源 == 14 [http://secuse.nchc.org.tw/jspservlet/u1004.vdi 下載 virtualbox 的硬碟檔] 15 * 此硬碟檔為ubuntu 10.04 版本,已經調整好教材,請用virtualbox 3.2.2 以上版本掛載 16 17 == 1.B 自行下載資源 == 17 18 1. [http://secuse.nchc.org.tw/jspservlet/jspservlet%e5%88%9d%e9%9a%8e.pdf 下載 pdf 手冊][[BR]] 18 19 … … 25 26 已將tomcat 安裝於 /opt/tomcat/ 目錄下 26 27 27 == 2.1 建立目錄 ==28 == 2.1 建立目錄 == 28 29 29 30 {{{ … … 33 34 }}} 34 35 35 == 2.2 第一個程式:HelloServlet.java ==36 == 2.2 第一個程式:HelloServlet.java == 36 37 37 38 {{{ … … 71 72 }}} 72 73 73 == 2.2編譯:HelloServlet.java檔 ==74 == 2.3 編譯:HelloServlet.java檔 == 74 75 75 76 {{{ … … 78 79 }}} 79 80 80 == 2.3製作佈署描述檔:web.xml ==81 == 2.4 製作佈署描述檔:web.xml == 81 82 82 83 {{{ … … 104 105 }}} 105 106 106 == 2. 4啟動web容器:tomcat ==107 == 2.5 啟動web容器:tomcat == 107 108 108 109 {{{ … … 111 112 }}} 112 113 113 == 2. 5用瀏覽器測試 ==114 == 2.6 用瀏覽器測試 == 114 115 115 116 [http://localhost:8080/FirstServlet/hello.do?name=caterpillar] … … 118 119 119 120 121 == 3. 練習 == 122 123 如果程式碼的第一行多了package宣告,要如何編譯執行 124 {{{ 125 #!java 126 package tw.org.nchc.opsrc; 127 import java.io.IOException; 128 import java.io.PrintWriter; 129 import javax.servlet.ServletException; 130 import javax.servlet.http.HttpServlet; 131 import javax.servlet.http.HttpServletRequest; 132 import javax.servlet.http.HttpServletResponse; 133 134 public class HelloServlet extends HttpServlet { 135 protected void doGet(HttpServletRequest request, 136 HttpServletResponse response) 137 throws ServletException, IOException { 138 response.setContentType("text/html;charset=UTF-8"); 139 PrintWriter out = response.getWriter(); 140 String name = request.getParameter("name"); 141 out.println("<html>"); 142 out.println("<head>"); 143 out.println("<title>Hello Servlet</title>"); 144 out.println("</head>"); 145 out.println("<body>"); 146 out.println("<h1> Hello! " + name + " !</h1>"); 147 out.println("</body>"); 148 out.println("</html>"); 149 out.close(); 150 } 151 } 152 }}} 120 153 121 154 122 155 123 124 125