如何创建scriptlet?我唯一想到的是如果你有一门课
public class YourScriptlet extends JRDefaultScriptlet {
public void afterDetailEval() throws JRScriptletException {
// your code here
}
}
您可以为另一个对象添加构造函数和私有成员,该对象充当jasper上下文之外所需的任何内容的容器,如下所示
要跟踪计数的某个对象(或需要跟踪的任何对象)
public class YourInfoObject {
private final AtomicInteger count = new AtomicInteger();
public int increment() {
return this.count.incrementAndGet();
}
public int get() {
return this.count.intValue();
}
public void set(int value) {
this.count.set(value);
}
}
带有构造函数的scriptlet类
public class YourScriptlet extends JRDefaultScriptlet {
private final YourInfoObject obj;
public YourScriptlet(YourInfoObject obj) {
this.obj = obj;
}
public void afterDetailEval() throws JRScriptletException {
// your code here
obj.set(count);
}
}
然后,从其他任何地方(带有对象引用的servlet)可以访问该值。