1. احصل على المسار في ملف Java
thread.currentThread (). getContextClassloader (). getResource ("") // احصل
classloader.getSystemResource ("")
class_name.class.getClassloader (). getResource ("")
class_name.class .getResource ("/")
class_name.class .getResource ("") // احصل على المسار الذي توجد فيه الفئة الحالية
System.getProperty ("user.dir") // احصل على المسار المطلق إلى الدليل الجذر للمشروع
System.getProperty ("java.class.path") // احصل على مسار ClassPath و Package
المطبوعات كما يلي:
ملف:/f:/work_litao/uri_test/webcontent/web-inf/clistes/
ملف:/f:/work_litao/uri_test/webcontent/web-inf/clistes/
ملف:/f:/work_litao/uri_test/webcontent/web-inf/clistes/
ملف:/f:/work_litao/uri_test/webcontent/web-inf/clistes/
ملف:/f:/work_litao/uri_test/webcontent/web-inf/classes/com/xml/imp/
F: work_litaouri_test
F: work_litaouri_testwebcontentweb-infclasses ؛
2. الحصول على المسارات النسبية والمطلقة للتطبيق الحالي في JSP
المسار المطلق المقابل لدليل الجذر: request.getRequesturi ()
المسار المطلق للملف: application.getRealPath (request.getRequesturi ()) ؛
المسار المطلق لتطبيق الويب الحالي: application.getRealPath ("/") ؛
احصل على الدليل العلوي للملف المطلوب: ملف جديد (application.getRealPath (request.getRequesturi ())). getParent ()
3. الحصول على المسارات النسبية والمطلقة للتطبيق الحالي في servlet
المسار المطلق المقابل لدليل الجذر: request.getServletPath () ؛
المسار المطلق للملف: request.getSession (). GetServletContext ().
المسار المطلق لتطبيق الويب الحالي: servletConfig.getServletContext (). getRealPath ("/") ؛
(يتم الحصول على كائن ServletContext بعدة طرق:
javax.servlet.http.httpsession.getServletContext ()
javax.servlet.jsp.pagecontext.getServletContext ()
javax.servlet.servletconfig.getServletContext ()
)
ما سبق هو المحتوى الكامل لهذه المقالة ، أتمنى أن تنال إعجابك.
يرجى قضاء بعض الوقت لمشاركة المقالة مع أصدقائك أو ترك تعليق. سنشكر بإخلاص على دعمكم!