web_02Java ee实现验证码,网站访问次数功能

Web

  Web_02版本:
    实现功能
      1,验证码
      2,网站访问次数统计
  设计内容
    1,servlet
    2,jsp
    3,js
  *重点
    1,验证码相关:
      1,Servlrt类实现验证码的生成
        CheckCodeServlet类:

      2,jsp页面中调用生成的验证码

        <script type="text/javascript">
        function flushCheckCode(obj) {
          obj.src = (obj.src + '?' + new Date())
        }
        </script>


        <tr>
          <td>
            验证码:
          </td>
          <td>
            <input type="text" name="checkCode" placeholder="CheckCode"/>
          </td>
        </tr>
        <tr>
          <td>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <img src="checkCode.jpg" onclick=flushCheckCode(this) alt="点击刷新验证码" />
          </td>
        </tr>

    2,网站访问次数统计
       1,CounterServlet类
          统计访问次数,存储在服务器下的文本中,重启服务器数据不会丢失。
        2,jsp页面中显示访问次数

        <%@ page import="org.servlet.CounterServlet" %>
        <%
        CounterServlet CountFileHandler=new CounterServlet();//创建对象
        int count=0;
        if(application.getAttribute("count")==null){
          count=CountFileHandler.readFile(request.getRealPath("/")+"count.txt");//读取文件获取数据赋count
          application.setAttribute("count",new Integer(count));
        }
        count=(Integer)application.getAttribute("count");
        if(session.isNew()) ++count;
        application.setAttribute("count",count);
        CountFileHandler.writeFile(request.getRealPath("/")+"count.txt", count);//更新文件记录
       %>

项目结构图:


项目效果图:

 

原文地址:https://www.cnblogs.com/HPioneer/p/6530930.html