본문 바로가기
개발 공부 Today I Learned

[국비 51일차 TIL] 관리자페이지에서 IP 확인하기

by 개발자신입 2024. 2. 1.
반응형

 

 

 

adminIp

 

package com.coffee.admin;


import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.coffee.dao.AdminDAO;

@WebServlet("/admin/adminIp")
public class AdminIp extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public AdminIp() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println(request.getParameter("ip"));
		AdminDAO dao = new AdminDAO();
		
		List<Map<String, Object>> list1 = dao.ipList();
		request.setAttribute("list1", list1);
		
		request.setAttribute("list2", dao.mostConnectedIP5());
		request.setAttribute("list3", dao.latestAccessIP10());
		List<Map<String, Object>> list = null;
		
		if(request.getParameter("ip") != null) {
			list = dao.ipList(request.getParameter("ip"));
		} else {
			list = dao.ipList();
		}
		
		RequestDispatcher rd = request.getRequestDispatcher("/admin/adminIp.jsp");//파일 있는 경로
		rd.forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

}

 

 

adminip.jsp

 

 

<!-- 구글 차트 Load the AJAX API-->
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
      google.charts.load('current', {'packages':['corechart']});
      google.charts.setOnLoadCallback(drawChart);

      function drawChart() {

    	    var data = google.visualization.arrayToDataTable([
    	        ['ip', '접속 수'],
    	        <c:forEach items="${list2}" var="row1">
    	          ['${row1.iip}', ${row1.count}],
    	        </c:forEach>
    	      ]);

        var options = {
          title: 'ip를 확인하자'
        };

        var chart = new google.visualization.PieChart(document.getElementById('piechart'));

        chart.draw(data, options);
      }
    </script>
</head>

<body>
<h1  style="color:white; font-size: 30px;font-weight: bolder;">IP 관리</h1>
	<div class="wrap">
		<!-- menu -->
		<%@ include file="menu.jsp" %>
		<!-- 본문내용 -->
		<div class="main">
			<article>
				<h2>IP 관리</h2>
				0. 중복없이 ip리스트 뽑기 
				<!-- SELECT DISTINCT iip FROM iplog  -->
				
               <h2>가장 많이 접속한 ip</h2>
            <table>
            <c:forEach items="${list2 }" var="row1">
            <tr>
                  <td>${row1.iip }</td>
                  <td>${row1.count }</td>
            </tr>
            </c:forEach>
            </table>
            <!-- 그래프로 그리기 -->
            <div id="piechart" style="width: 900px; height: 500px;"></div>
                  
             <h2>가장 최근 접속 ip</h2>
            <table>
            <c:forEach items="${list3 }" var="row2">
            <tr>
                  <td>${row2.iip }</td>
                  <td>${row2.idate }</td>
            </tr>
            </c:forEach>
            </table>

 

반응형

댓글