简体   繁体   中英

can jsp access .jar files?

I have a properties file in JAR file.

In my web application, I want to access this properties file from the jsp within web application.

I try doing it with the following code, but results in FileNotFoundException

Properties properties = new Properties();
properties.load(new FileInputStream("myfile.properties"));

How can i access the file from JAR which is in my classpath within scriptlets in jsp?

Thanks in advance.

Not this way. You can try to get the Input Stream by using 'getResourceAsStream' functionality.

Read about this Here

Hope this helps

Yes you can using

InputStream in = this.getClass().getClassLoader().getResourceAsStream("//myfile.properties"); 

Make sure your jar file which has this property file is in classpath.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM