简体   繁体   English

可以jsp访问.jar文件吗?

[英]can jsp access .jar files?

I have a properties file in JAR file. 我在JAR文件中有一个属性文件。

In my web application, I want to access this properties file from the jsp within web application. 在我的Web应用程序中,我想从Web应用程序中的jsp访问此属性文件。

I try doing it with the following code, but results in FileNotFoundException 我尝试使用以下代码,但导致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? 如何从jsp中的scriptlets中的classpath JAR访问该文件?

Thanks in advance. 提前致谢。

Not this way. 不是这样的。 You can try to get the Input Stream by using 'getResourceAsStream' functionality. 您可以尝试使用'getResourceAsStream'功能获取输入流。

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. 确保具有此属性文件的jar文件位于类路径中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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