📄 simple_showvote.jsp
字号:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.text.NumberFormat"%>
<!--创建并调用bean(com.wxpn.tutorial.servlet.Counter)-->
<jsp:useBean id="counter" class="com.wxpn.tutorial.servlet.Counter"
scope="request">
</jsp:useBean>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>投票结果</title>
</head>
<body>
<%//获取绝对路径
String txtPath = request.getRealPath("a.txt");
//调用counter对象的readFile方法来读取文件a.txt中的计数
String count = counter.readFile(txtPath);
int counter_A = Integer.parseInt(count);
txtPath = request.getRealPath("b.txt");
//调用counter对象的readFile方法来读取文件b.txt中的计数
count = counter.readFile(txtPath);
int counter_B = Integer.parseInt(count);
txtPath = request.getRealPath("c.txt");
//调用counter对象的readFile方法来读取文件c.txt中的计数
count = counter.readFile(txtPath);
int counter_C = Integer.parseInt(count);
int _total = counter_A + counter_B + counter_C;
double total=_total;
NumberFormat nf = NumberFormat.getPercentInstance();
%>
<table width="80%" border="0" align="center">
<tr>
<td align="center" valign="middle">现在总共投票<%=_total%></td>
</tr>
</table>
<table>
<tr >
<td align="center" width="<%=(counter_A/total)*100%>" bgcolor="#000000"></td>
<td><%=nf.format(counter_A/total)%></td>
</tr>
</table>
<table>
<tr>
<td align="center" width="<%=(counter_B/total)*100%>" bgcolor="#000000"></td>
<td><%=nf.format(counter_B / total)%></td>
</tr>
</table>
<table>
<tr>
<td align="center" width="<%=(counter_C/total)*100%>" bgcolor="#000000"></td>
<td><%=nf.format(counter_C / total)%></td>
</tr>
</table>
<table width="80%" border="0" align="center">
<tr>
<td align="center" valign="middle"><a href="simple_vote.jsp">我要投票</a></td>
</tr>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -