使用esapi时报错:
Not found in 'org.owasp.esapi.resources' directory or file not readable: C:\Users\ccg\Desktop\esapi\ESAPI.properties
Not found in SystemResource Directory/resourceDirectory: .esapi\ESAPI.properties
Not found in 'user.home' (C:\Users\ccg) directory: C:\Users\ccg\esapi\ESAPI.properties
Loading ESAPI.properties via file I/O failed. Exception was: java.io.FileNotFoundException
Exception in thread "main" org.owasp.esapi.errors.ConfigurationException: java.lang.reflect.InvocationTargetException SecurityConfiguration class (org.owasp.esapi.reference.DefaultSecurityConfiguration) CTOR threw exception.
Attempting to load ESAPI.properties via the classpath.
at org.owasp.esapi.util.ObjFactory.make(ObjFactory.java:129)
ESAPI.properties could not be loaded by any means. Fail. Exception was: java.lang.IllegalArgumentException: Failed to load ESAPI.properties as a classloader resource.
解决方法:将esapi.jar添加到项目之后,还要引入ESAPI.properties和validation.properties两个文件。
如何引入这两个文件,第一种方法:建立一个Resources类型的文件夹,把这两个文件直接甩里面即可。
第二种方法:在myeclipse中,选中某个项目,然后在工具栏中选择"Run-->Run Confgurations“,然后在对话框的右边选择"Arguments,然后在VM arguments中输入
if(customDirectory != null && f.canRead()) { this.logSpecial("Found in \'org.owasp.esapi.resources\' directory: " + f.getAbsolutePath()); return f; } else { this.logSpecial("Not found in \'org.owasp.esapi.resources\' directory or file not readable: " + f.getAbsolutePath()); 其中有:
private static String customDirectory = System.getProperty("org.owasp.esapi.resources");查资料得:我的理解是这样的,在myeclipse中,选中某个项目,然后在工具栏中选择"Run-->Run Confgurations“,然后在对话框的右边选择"Arguments,然后在VM arguments中输入-Dproperty.name=value,这样,在你的代码中使用System.getProperty(property.name)即可以获取value的值。
希望可以帮助到你们。