1. ホーム
  2. Web プログラミング
  3. JSP プログラミング

JSP統計のウェブサイトの訪問者を使用する方法を教える

2022-01-16 17:58:51

訪問者のカウント1

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-/W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" >    
<title>My JSP 'sxtcount.jsp' starting page</title>   
	<! --
	<link rel="stylesheet" type="text/css" href="styles.css" rel="external nofollow" rel=" external nofollow" >
	-->
  </head>
  <body>
       <! -- declarative -->
       <%!
        int count=0;
       // out.print("You are the first "+count+"person to visit this site");   
       public void a(){
       }
       %> 
       <! --mini-script -->
       <%
  count++; 
  out.print("You are the first "+count+"person to visit this site");
       %>
       <! --expression -->
       <%-- <%=count %> --%>
  </body>
</html>
<! --
Summary
  [1] The essence of jsp is a servlet (that is, a class) single instance multi-threaded program
  [2] There are 3 ways to write java code in a jsp page
     A、Small script
     B、expression
     C、Declarative
  
  [3] The difference between small script and declarative
     A. The variables declared in small scripts are local variables, and the variables declared in declarative are member variables.
     B. You can't define methods in small scripts, but you can define methods in declarative scripts.
     C. The built-in objects of jsp can be used in small scripts, but not in declarative scripts.  
     [4] All comments
      A. 3 kinds of comments in java
      B、Comment in HTML
      C、comment in JSP   
       Recommend to use jsp comments
       Advantage: save network bandwidth and increase the speed of access
 -->


訪問者数をカウントする 2

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-/W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" >    
    <title>My JSP 'sxtcount.jsp' starting page</title>
	<! --
	<link rel="stylesheet" type="text/css" href="styles.css" rel="external nofollow" rel=" external nofollow" >
	-->
  </head>  
  <body>
      <! -- dynamic include --- action marker -->
      <%-- <jsp:include page="head.jsp"></jsp:include> --%>
      <! --Static include ---directive identifier -->
      <%@include file="head.jsp" %>
        <div style="height: 400px">
         <! -- declarative -->
       <%!
        int count=0;
        %>
       <! --mini script -->
       <%
            count++;
            out.print("You are the first "+count+"person to visit this site");
       %>
        </div>       
       <jsp:include page="foot.jsp"></jsp:include>
  </body>
</html>
<! -- 
  Differences between dynamic inclusion and static inclusion.
  [1] Static inclusion copies the code into the main file as is, dynamic inclusion is the equivalent of a method call  
  [2] Static inclusion does not allow variables with the same name to exist in the file and the main file, while dynamic inclusion does.
  [3] Static introduction does not generate class files, while dynamic introduction generates class files.
  [4] The timing of static introduction is the first stage, while the timing of dynamic introduction is the third stage.
 Commonalities.
  Both enable the introduction of web pages -->


概要

今回の記事は、JSPを使ってホームページの訪問者数をカウントする方法についてです。JSPの統計については、過去の記事を検索していただくか、引き続き以下の記事をご覧ください。