티스토리 뷰
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>
'Programing > JSP' 카테고리의 다른 글
JSP2 - [GusetBook 프로젝트 ] (0) | 2017.09.03 |
---|---|
JSP - [주민등록번호 유효성 검사 프로젝트 ] (0) | 2017.06.21 |
JSP1-[온라인 투표 프로젝트 3 - pollWrite.jsp/pollWrite.java] (0) | 2017.06.14 |
JSP1-[온라인 투표 프로젝트 2 - 디자인 CSS] (0) | 2017.06.14 |
JSP1-[온라인 투표 프로젝트 1 - pollRead.jsp/pollRead.jsp] (0) | 2017.06.12 |