Hi All,
I have one servlet class which setMessage() method as follows for global count of users accessing a site.here we want to restrict the number of users.so that we used to avoid that.
public void setMessage(String msg){
str = msg;
System.out.println("Testing of servlet in isde setMessage*************"+msg);
ServletContext context =null;
try{
context = getServletContext();
}catch(Exception e){
e.printStackTrace();
}
Integer count = (Integer)context.getAttribute("SessionCount");
if(count != null){
int ct = count.intValue();
ct++;
context.setAttribute("SessionCount",new Integer(ct));
System.out.println("Count starting from exsiting session count now the updated in the applciation scope*************"+ct);
}else{
context.setAttribute("SessionCount",new Integer(1));
System.out.println("Count starting for session user is new so now it is 1");
}
}
java.lang.NullPointerException
at javax.servlet.GenericServlet.getServletContext(GenericServlet.java:204)
at com.panache.pcalife.action.TestServlet.setMessage(TestServlet.java:20)
at com.panache.pcalife.action.AuthenticateAction.execute(AuthenticateAction.java:109)
While accessing from the URL,ServletContext throws Nullpointer........
Please help me to overcome this problem
Regards
Vijay