Changes between Version 8 and Version 9 of waue/2010/0608
- Timestamp:
- Jun 8, 2010, 2:30:18 PM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
waue/2010/0608
v8 v9 9 9 [[PageOutline]] 10 10 11 = 一. 下載資源 = 11 本篇為此書第二章的實做練習 12 13 * [http://secuse.nchc.org.tw/jspservlet/jspservlet%e5%88%9d%e9%9a%8e.pdf 下載 pdf 手冊][[BR]] 14 15 = 零. 下載資源 = 12 16 == 1.A 用 virtualbox 虛擬機器 == 13 17 … … 16 20 17 21 == 1.B 自行下載資源 == 18 1. [http://secuse.nchc.org.tw/jspservlet/jspservlet%e5%88%9d%e9%9a%8e.pdf 下載 pdf 手冊][[BR]] 22 19 23 20 24 2. [http://secuse.nchc.org.tw/jspservlet/tomcat-6.0.26.tar.gz 下載tomcat 6.5] … … 22 26 3. [http://secuse.nchc.org.tw/jspservlet/eclipse-SDK-3.5.2-linux-gtk.tar.gz 下載 eclipse 3.5 linux版] 23 27 24 = 二. 實做簡單的 servlet 範例=28 = 範例一 = 25 29 26 已將tomcat 安裝於 /opt/tomcat/ 目錄下 30 * 2.1.1~ 2.1.3 的範例 (p2-1~p2-10) 27 31 28 32 == 2.1 建立目錄 == 33 34 已將tomcat 安裝於 /opt/tomcat/ 目錄下 29 35 30 36 {{{ … … 120 126 ------------ 121 127 122 = 練習 =128 == 練習 == 123 129 124 130 如果程式碼的第一行多了package宣告,要如何編譯執行 … … 126 132 #!java 127 133 package tw.org.nchc.opsrc; 128 import java.io.IOException; 129 import java.io.PrintWriter; 130 import javax.servlet.ServletException; 131 import javax.servlet.http.HttpServlet; 132 import javax.servlet.http.HttpServletRequest; 133 import javax.servlet.http.HttpServletResponse; 134 #其他相同省略~~~ 135 }}} 134 136 135 public class HelloServlet extends HttpServlet { 136 protected void doGet(HttpServletRequest request, 137 HttpServletResponse response) 138 throws ServletException, IOException { 139 response.setContentType("text/html;charset=UTF-8"); 140 PrintWriter out = response.getWriter(); 141 String name = request.getParameter("name"); 142 out.println("<html>"); 143 out.println("<head>"); 144 out.println("<title>Hello Servlet</title>"); 145 out.println("</head>"); 146 out.println("<body>"); 147 out.println("<h1> Hello! " + name + " !</h1>"); 148 out.println("</body>"); 149 out.println("</html>"); 150 out.close(); 151 } 152 } 137 = 範例二 = 138 139 * 2.1.4 的範例 (p2-10 ~ p2-11) 140 141 {{{ 142 cd /opt/tomcat/webapps 143 jar cvf ~/servlet1.war servlet1/* 144 gedit /opt/tomcat/conf/web.xml 153 145 }}} 154 146 155 147 148 {{{ 149 <?xml version='1.0' encoding='utf-8'?> 150 <tomcat-users> 151 <role rolename="tomcat"/> 152 <role rolename="manager"/> 153 <user username="nutchuser" password="nutchez" roles="tomcat,manager"/> 154 </tomcat-users> 155 }}} 156 156 157 刪除/opt/tomcat/webapps/servlet1/ 整個專案,再重開tomcat 158 {{{ 159 /opt/tomcat/bin/shutdown.sh 160 /opt/tomcat/bin/startup.sh 161 }}} 162 163 先開啟[http://localhost:8080/servlet1/hello.do?name=caterpillar] 164 165 網頁錯誤 166 167 [http://localhost:8080/manager/html/list] 168 169 佈署~/servlet1.war檔(圖形介面難以文字描述) 170 171 開啟[http://localhost:8080/servlet1/hello.do?name=caterpillar] 172 173 有看到範例一的網頁即完成 174 175 == 練習 == 176 ,將專案建立、開啟、停止、移除 177