看板 Web_Design 關於我們 聯絡資訊
程式如下 <%! public String test() { String rootPath = application.getRealPath("/"); return rootPath ; } %> <% String rootPath = application.getRealPath("/"); out.print(rootPath); %> 為什麼 application.getRealPath("/") 在 test() function 裡無法work, 但在test() 外是可以work的. 試了很多功能, 似乎在 function裡都不能使用. google也找不到答案, 我想應該是我方向錯了, 我是jsp 新手, 麻煩指教, 非常感謝~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.130.162.129
opoepev:test不是保留字嗎? 換個function名稱看看 01/03 20:19
LaPass:關鍵在於... 妳有沒有搞清楚 <% %><%! %>的差別 01/03 22:31
LaPass:以及.... application 只在 <% %>中可用 01/03 22:33
smsim:那可以告訴我如果我要在function裡用application 01/04 09:56
smsim:應該怎麼寫嗎? 或者應該朝那個方向去找資料 01/04 09:57
LaPass:this.getServletContext(); 我是建議你把J2EE從頭看一次 01/04 11:06
smsim:有找到一個教學, 我想我搞懂了, jsp是要跟servlet配合的 01/04 17:06
smsim:給需要的人參考 01/04 17:07