| | 36 | * 第四步驟做完,則可以透過 Eclipse 的 Servers 這個 window ,對 tomcat 進行管控 |
| | 37 | |
| | 38 | * 5.1 Servlets |
| | 39 | |
| | 40 | 雖然 new project 起來,web項目只有 靜態 與 動態 網頁專案可以建立,但要建立檔案,web 內則有許多檔案類型可以建立。 |
| | 41 | |
| | 42 | 開發 java 網頁的視野是用 ''' Java EE ''' 這個 Perspective |
| | 43 | |
| | 44 | 作者的project name 為 de.vogella.wtp.filecounter ,我簡化project 名稱為 jsp |
| | 45 | |
| | 46 | * 5.2 Creating Data Access Object |
| | 47 | |
| | 48 | de.vogella.wtp.filecounter.dao 改為 jsp |
| | 49 | |
| | 50 | {{{ |
| | 51 | #!txt |
| | 52 | file -> new -> other ==> java .( package ) -> next ==> Name: dao |
| | 53 | }}} |
| | 54 | |
| | 55 | 之後在 Java Resources:src 內就出現剛剛建立的package : dao |
| | 56 | |
| | 57 | 接著在dao 圖示點選右鍵 -> new -> class ==> 步驟省略, 將 FileDao.java 建好後,填入作者給的code , 5.2 完成 |
| | 58 | |
| | 59 | * 5.3. Creating the Servlet |
| | 60 | |
| | 61 | 雖然在 WebContent 的目錄點右鍵新增 FielCounter 檔,但程式還是會產生在 Java Resources 資料夾內 |
| | 62 | |
| | 63 | 而透過servlet 的 wizard ,Eclipse 幫我們產生出來的 java檔會有 doGet, doPost, 建構值, 以及 serialVersionUID |
| | 64 | |
| | 65 | * 5.4. Run |
| | 66 | |
| | 67 | run 的時候 選 run on server ,並選擇我們之前build 好的server 即可,可以run 的話,在原始碼旁邊會跳出執行的網頁 |
| | 68 | |
| | 69 | 挑選server 時,可以選 always use the server |
| | 70 | |
| | 71 | 有將印出的字改成中文,會有亂碼問題,即使 server.xml 已經正確配置成 utf-8 |
| | 72 | |
| | 73 | 以前看到的servlet code 再用 out.print 時,需要 <html><body> </body> ...等html的標籤印出,但這邊的code 不用 |
| | 74 | |
| | 75 | |
| | 76 | * 6. JavaServer Pages (JSPs) |
| | 77 | |
| | 78 | 原作者要我們新增一個專案來測試,但我在上個專案下,又建立一個 jsp package ,然後把 test.jsp 放在這個 package 內,無法讀取的到 |
| | 79 | |
| | 80 | 只好用作者的方法繼續測試,結果http://localhost:8080/de.vogella.wtp.jspsimple/FirstJSP.jsp 頁面還是無法出現 |
| | 81 | |
| | 82 | |
| | 83 | |
| | 84 | = 重點 = |
| | 85 | * 用純 eclipse 3.5 ,update install wtp(需加入更新網址),還要記得勾選"在原本galielo 源碼內 web 項目中的專案" 來安裝 |
| | 86 | * 開發 java 網頁的視野是用 ''' Java EE ''' 這個 Perspective |
| | 87 | * 透過精靈建 project,web項目只有 靜態 與 動態 網頁專案,但要建立檔案,web 項目內則有許多檔案類型可以建立 |
| | 88 | * Java Resources:src 會有我們new 出來的 java 檔 |
| | 89 | * run on server |
| | 90 | |