write.jsp
来自「投票调查 一个很简单的投票调查JSP,能在界面上用条状图显示不同问题的对比关系!」· JSP 代码 · 共 51 行
JSP
51 行
<%
String tmp = null;
int choice = -1;
int[] count = new int[4];
tmp = request.getParameter("choice");
if (tmp==null){
} else {
choice = new Integer(tmp).intValue();
}
/////////////
String s = request.getRealPath("count.txt");
if(choice>=0){
String strTemp = null;
int i;
java.io.RandomAccessFile rf = null;
try {
rf = new java.io.RandomAccessFile(s,"r");
} catch(Exception e)
{
System.out.println(e);
System.exit(0);
}
for(i=0;i<4;i++)
{
try {
strTemp = rf.readLine();
} catch(Exception e) {
strTemp = "0";
}
if(strTemp==null)strTemp = "0";
count[i] = Integer.parseInt(strTemp);
}
count[choice]++;
try {
java.io.PrintWriter pw = new java.io.PrintWriter(new java.io.FileOutputStream(s));
for (i=0;i<4;i++){
pw.println(count[i]+"");
}
pw.close();
} catch(Exception e) {
System.out.println("Write file error:"+e.getMessage());
}
}
response.sendRedirect("index.jsp");
%>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?