您现在的位置是:主页 > news > 做网站有免费的服务器吗/数据推广公司

做网站有免费的服务器吗/数据推广公司

admin2025/6/6 10:55:08news

简介做网站有免费的服务器吗,数据推广公司,绵阳科技网站建设,北京微网站建设设计服务效果图 主页 第一次访问 第二次访问 切换浏览器&#xff0c;数据连续累加&#xff08;全局作用域&#xff0c;服务器不重启&#xff0c;数据会一直保留&#xff09; html代码 <h2><a href"CountServlet">点我查看网站访问量</a></h2>Count…

做网站有免费的服务器吗,数据推广公司,绵阳科技网站建设,北京微网站建设设计服务效果图 主页 第一次访问 第二次访问 切换浏览器&#xff0c;数据连续累加&#xff08;全局作用域&#xff0c;服务器不重启&#xff0c;数据会一直保留&#xff09; html代码 <h2><a href"CountServlet">点我查看网站访问量</a></h2>Count…

效果图

  • 主页
    在这里插入图片描述
  • 第一次访问
    在这里插入图片描述
  • 第二次访问
    在这里插入图片描述
  • 切换浏览器,数据连续累加(全局作用域,服务器不重启,数据会一直保留)

html代码

 <h2><a href="CountServlet">点我查看网站访问量</a></h2>

CountServlet代码

package count;import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;public class CountServlet extends HttpServlet {protected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {int totalCount=1;//默认访问量为1//获取网站访问量Object count = request.getServletContext().getAttribute("count");//判断count是否为null,不为null表示曾经访问过,直接将count赋值给totalCountif(count!=null) {totalCount=(int)count;}//访问次数累加request.getServletContext().setAttribute("count",totalCount+1);response.getWriter().println("网站访问量为:"+totalCount);	//输出到界面}}