读书人

WEB-INF下取properties文件提示存取

发布时间: 2012-01-12 22:11:58 作者: rapoo

WEB-INF下取properties文件提示存取被拒
我有DB.JAVA

package db;

import java.io.*;
import java.sql.*;
import java.util.*;
import javax.xml.parsers.*;
import java.net.URL;

import org.w3c.dom.*;

/**
* : 擂踱蟀 Copyright (c) 2005-2008 Wang Xining
*
* @author
* @version 1.0
*/

public class DB {
static String driver = null;

static String server = null;

static String dbuser = null;

static String dbpassword = null;

static int minconn = 0;

static int maxconn = 0;

static double maxconntime = 0.1D;

static String log_properties = null;

static ConnectionPool p = null;

private static String resourcePath;

private static Properties configProperties = System.getProperties();


static
{
int pos=0;

URL url = DB.class.getResource( "DB.class ");

String pkgName = DB.class.getPackage().getName();

do
{
pos = pkgName.indexOf( ". ");
if(pos> 0)
{
pkgName = pkgName.substring(0,pos)+ "/ "+pkgName.substring(pos+1);
}

}
while(pos> 0);

String filePath = url.getFile();

String appPath = filePath.substring(0,filePath.indexOf( "/classes/ "+pkgName));

resourcePath = appPath+ "/resources ";

try
{
configProperties.load(new FileInputStream(DB.getResourcePath()));
}
catch(FileNotFoundException e)
{

e.printStackTrace();


}
catch(IOException ex)
{
ex.printStackTrace();
}

}




public static void getAtrributes()
{

try
{
driver = getProperty( "driver ");
server = getProperty( "server ");
dbuser = getProperty( "dbuser ");
dbpassword = getProperty( "dbpassword ");
minconn = Integer.parseInt(getProperty( "minconn "));
maxconn = Integer.parseInt(getProperty( "maxconn "));
maxconntime = Double.parseDouble(getProperty( "maxconntime "));

}
catch(Exception e)
{
System.out.println( "Problem parsing the file "+e);
}
}


/**
* Create a connectionpool
*/
public static ConnectionPool getConnPool() {
try {
if (p == null) {
p = new ConnectionPool(driver, server, dbuser, dbpassword,
minconn, maxconn, maxconntime);
}
return p;
} catch (Exception e) {
e.printStackTrace();
}

return null;
}


public static String getResourcePath()
{
return resourcePath;
}

public static Properties getConfigProperties()
{
return configProperties;
}

public static String getProperty(String name)
{
return getConfigProperties().getProperty(name);
}

}
它取WEB-INF/resources/config.properties文件中的相mysql接量,但是行,文件存取被拒!
WHY!
THINKS!

[解决办法]
文件不存在?用户权限不够??

读书人网 >Java Web开发

热点推荐