Servlet实现访问次数的例子_JSP技巧_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

Servlet实现访问次数的例子

作者:黑客防线网安JSP教程基地 来源:黑客防线网安JSP教程基地 浏览次数:0

本篇关键词:例子次数访问实现
黑客防线网安网讯:Servlet实现访问次数的例子!这个类实现访问次数。显示访问次数!看是第几次访问!

  //ShowTimesServlet.java /*Servlet实现访问次数的例子!*/
import java.io.*;
import java.util.zip.*;
import javax.servlet.*;
import javax.servlet.http.*;
/*
 这个类实现访问次数显示访问次数!看是第几次访问!
*/
public class ShowTimesServlet extends HttpServlet {

   public void doGet(HttpServletRequest request,HttpServletResponse response)
               throws ServletException, java.io.IOException {

              response.setContentType("text/html");
   HttpSession session = request.getSession();
   String heading;
   Integer accessCount =(Integer)session.getAttribute("accessCount");
   if(accessCount == null) {
    accessCount = new Integer(0);
    heading = "Welcom,You are first time to visit!";
   }
   else {
    heading = "Welcome Backer";
    accessCount = new Integer(accessCount.intValue()+1);
   }
      session.setAttribute("accessCount",accessCount);
   PrintWriter out = response.getWriter();
   out.println("The title:"+heading);
   out.println("Access count: "+accessCount);
 }

   public void doPost(HttpServletRequest request,HttpServletResponse response)
               throws ServletException, java.io.IOException {
  doGet(request,response);
 }

  }

    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-16384-1.html
网站维护教程更新时间:2023-02-17 17:28:20  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer