求教!用Servlet编写计数器问题!!!!急啊个位大哥!!!
代码如下
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class Servlet1 extends HttpServlet {
public Servlet1() {
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private static final String CONTENT_TYPE = "text/html; charset=GBK ";
//Initialize global variables
public void init() throws
ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException,
IOException {
int i=0;
Integer num=new Integer(0);
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
ServletContext context=this.getServletContext();
num=(Integer)context.getAttribute( "count ");
if(num==null)
{
i=1;
num=new Integer(1);
}
else
{
i=num.intValue()+1;
num=new Integer(num.intValue()+1);
}
context.setAttribute( "count ",num);