当我运行我的应用程序场景时,ArrayList<String> dataVal
获取旧值意味着它们会在变量新值+上一个会话中显示一些不同的值。我使用下面的代码,我确实只放了所需的源代码,而不是所有的源代码。因此,请验证我的以下代码并确认我的源代码中出现了什么问题,该代码部署在Tomcat 7
上。
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.TimeZone;
import com.novell.nxpe.NxpeCondition;
import com.novell.nxpe.NxpeException;
import com.novell.nxpe.NxpeInformationContext;
import com.novell.nxpe.NxpeResponseContext;
import com.novell.nxpe.NxpeResult;
public class PolicyConditionExtnTemplate implements NxpeCondition {
ArrayList<String> dataVal = new ArrayList<String>();
@Override
public NxpeResult evaluate(NxpeInformationContext informationContext, NxpeResponseContext responseContext)
throws NxpeException {
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dt = new Date();
formatter.setTimeZone(TimeZone.getTimeZone("Canada/Eastern"));
String currentTime = formatter.format(dt);
System.out.println("PolicyConditionExtnTemplate : Date Time : " + currentTime);
NxpeResult res = NxpeResult.ConditionFalse;
System.out.println("dataVal : " + dataVal);
res = NxpeResult.ConditionTrue;
return res;
}
private void get_dataVal(DirContext eDirConn, Attributes att) {
try {
//dataVal.clear();
for (Enumeration<?> vals = att.get("descriptionVal").getAll(); vals.hasMoreElements();) {
String val = (String) vals.nextElement();
System.out.println("get_dataVal AD_dataVal : " + val);
if (val != null && !val.isEmpty()) {
dataVal.add(val);
}
System.out.println("get_dataVal dataVal : " + dataVal);
}
} catch (Exception e) {
System.out.println("Exception inside get_dataVal : " + e);
}
}
}
我还放了一些用于验证值的sysout,我可以在日志中看到它在下面的sysout中显示旧值
System.out.println("dataVal : " + dataVal);
如果我使用下面的代码,我在上面的源代码中评论过,它对我来说很好,但我想知道它发生的原因,因为没有其他参考这个特定的变量,他们可以增加他们的价值观。
dataVal.clear();
我使用的是Java 1.8.0_121。