普通java类文件如何访问WEB-INF目录下的文件,不是Servlet、JSP类文件...

发布网友 发布时间:1天前

我来回答

3个回答

热心网友 时间:1天前

你就用System.out.print();在控制台输出一下内容咯!例如一下就是访问配置文件并输出相应变量的方法
public void capturePropertys(String driver,String url,String user,String password){
Properties prop = new Properties();
InputStream is = a_connection_Propertys.class.getResourceAsStream("db.properties");
//getClass().getResourceAsStream("mysql.properties");
try{
prop.load(is);
}catch(IOException e)
{
System.out.println("[Dbconnection]打开 文件 出错");
}

this.jdbc = prop.getProperty(driver);
this.url = prop.getProperty(url);
this.user = prop.getProperty(user);
this.password = prop.getProperty(password);

System.out.println("jdbc="+this.jdbc);
System.out.println("url="+this.url);
System.out.println("user="+this.user);
System.out.println("password="+this.password);

}

热心网友 时间:1天前

普通java类访问WEB-INF目录下的文件的方法:
1、申明文件对象

File myConfigFile = new File(getClass().getProtectionDomain().getCodeSource().getLocation().getFile());
System.out.println("Finding calss path first then remove classes from the path " + myClass.getCanonicalPath().replaceFirst("classes", "")+"reportFIle/report01/reports.xml")
2、替换classes然后加入文件路径。
File f = new File(myClass.getCanonicalPath().replaceFirst("classes", "")+"reportFile/report01/reports.xml")
3、解析web-inf下的xml文件:
document = docBuilder.parse(new File(myClass.getCanonicalPath().replaceFirst("classes", "")+"reportFile/report01/reports.xml"));

热心网友 时间:1天前

标签
<%@ taglib uri="/WEB-INF/testTag.tld" prefix="tt" %>

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com