2010年3月22日 星期一

Import 討論

1. import 可有兩種方式
a. Using the jar file putting in the WEB-INF/lib/ directory
b. Using the .class putting in the WEB-INF/classes/

2. Then you will restart the tomcat to setting the classpath .


[reference about the import discuss]
http://www.javaworld.com.tw/jute/post/view?bid=6&id=47626&sty=3
若要將自己寫的class放在web應用程式的classes目錄下
則該class必須設定package
否則在jsp中 不論是直接new or 用
都會發生不認得該class的錯誤

第二點:
classes目錄以及其子目錄的class Tomcat並不會"自動幫你import"
但是tomcat會自動幫你將web應用程式下的classes目錄"自動加入classpath"
"自動幫你import" 和 "自動加入classpath" 是不同的
所以 若你在jsp中要使用你自訂在classes目錄下的class 但是你並沒有使用<%@ page import="..." %>的話
則 你在使用該class時 就必須指定該class的全名

沒有留言:

張貼留言