我有一个类 counterBean,我希望在我的 jsp 中实例化两个 counterBean 实例(用于两个单独的计数器)。我该怎么做?
编辑 - 添加代码
package beans;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean(name="CounterBean")
@SessionScoped
public class CounterBean implements Serializable
{
private static final long serialVersionUID = 1L;
private static int hitCount;
public CounterBean()
{
CounterBean.hitCount = 0;
}
public static int getCounter()
{
hitCount++;
return hitCount;
}
public static void setCounter(int hitCount)
{
CounterBean.hitCount = hitCount;
}
public static int getValue()
{
return hitCount;
}
}