请帮忙为下面这段代码写注释

来源:百度知道 编辑:UC知道 时间:2024/06/27 03:44:49
public class myservlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
int count;

//Initialize global variables
public void init(ServletConfig config) throws ServletException {
super.init(config);
String initial=config.getInitParameter("initial");
try{
count=Integer.parseInt(initial);
}catch(NumberFormatException e){
count=0;
}
System.out.println("计数器Servlet已初始化");
}

//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><tit

public class myservlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK"; //设置响应的内容类型及字符编码.
int count; 定义一个整型的变量,用于存放访问的次数的变量.

//Initialize global variables
public void init(ServletConfig config) throws ServletException {
super.init(config); //调用父类的构造方法初使化servlet,该方法在调用destory()方法之前只会执行一次.
String initial=config.getInitParameter("initial"); //调用 ServletConfig的getInitParameter方法从web.xml中取得参数名为initial的值,即记录了访问次数.
try{
count=Integer.parseInt(initial); //将其转换为整形.
}catch(NumberFormatException e){
count=0; //出现异常就初使化为0.
}
System.out.println("计数器Servlet已初始化");
}

//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE); //设置响应的类型.
PrintWriter out = response.getWriter(); //得到一个输出流,用于向客户端发