[問題] jsp function 問題

看板Web_Design作者 (crazyM)時間13年前 (2013/01/03 18:34), 編輯推噓2(207)
留言9則, 3人參與, 最新討論串1/1
程式如下 <%! 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

01/03 20:19, , 1F
test不是保留字嗎? 換個function名稱看看
01/03 20:19, 1F

01/03 22:31, , 2F
關鍵在於... 妳有沒有搞清楚 <% %><%! %>的差別
01/03 22:31, 2F

01/03 22:33, , 3F
以及.... application 只在 <% %>中可用
01/03 22:33, 3F

01/04 09:56, , 4F
那可以告訴我如果我要在function裡用application
01/04 09:56, 4F

01/04 09:57, , 5F
應該怎麼寫嗎? 或者應該朝那個方向去找資料
01/04 09:57, 5F

01/04 11:06, , 6F
this.getServletContext(); 我是建議你把J2EE從頭看一次
01/04 11:06, 6F

01/04 17:06, , 7F
有找到一個教學, 我想我搞懂了, jsp是要跟servlet配合的
01/04 17:06, 7F

01/04 17:07, , 9F
給需要的人參考
01/04 17:07, 9F
文章代碼(AID): #1GvLwt2g (Web_Design)