티스토리 뷰

1. pollResult.jsp 소스코드


<%@page import="java.text.DecimalFormat"%>
<%@page import="kr.koreait.olinePoll.PollRead"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>


<link rel="stylesheet" href="poll.css">


</head>
<body>


<%
 //1filename으로 poll.txt에 저장된 파일 불러오기
 String filename=application.getRealPath("/")+"poll.txt";
 
 //2 PollRead.pollRead로 파일에ArrayList 저장
 ArrayList<String> poll=PollRead.pollRead(filename);
 
 //3 litemCount 
 int itemCount=(poll.size()-1)/2;
 
 //4.totalCount
 int totalCount=0;
 


 for(int i=itemCount+1;i<poll.size();i++){
  totalCount +=Integer.parseInt(poll.get(i));
 }
 

// 복잡한 숫자들을 간단하게 만들어줌 
 DecimalFormat df1= new DecimalFormat("#,##0표");
 DecimalFormat df2 = new DecimalFormat("#,##0.00%");


%>



 <!-- 전체 득표 수 : <%=totalCount %> -->


<table width="550" align="center" border="0">
 <tr><th colspan="2" id="title"><%=poll.get(0) %></th></tr>
 <tr><td colspan="2" align="right"> 총 득표 수 : <%=df1.format(totalCount)%></td></tr>
 
<%
 for(int i=1; i <= itemCount; i++) {
  int pyo = Integer.parseInt(poll.get(itemCount + i)); // 득표수
  double per = (double)pyo / totalCount ;       // 득표율 
%>
 <tr>
  <td width="200"><%=poll.get(i) %>항목(<%=df1.format(pyo)%>(<%=df2.format(per)%>))</td>
  <td><hr color="red" size="20" width="<%= 340*per%>"align="left"></td>
 </tr>
  
  
<%  
 }
%>


<!-- 반복문에서 나와야함  -->
<tr>
 <td align="center" colspan="2">
  <input type="button" value="돌아가기 " onclick="location.href='pollRead.jsp'"/>
  
 </td>
</tr>


</table>
</body>
</html>



공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함