?? writefl.jsp
字號:
<%!
public int[] getNumber(String s)
{
int[] mCount = new int[4];
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";
mCount[i] = new Integer(strTemp).intValue();
}
return mCount;
}
public void setNumber(String s,int[] x)
{
try{
java.io.PrintWriter pw = new java.io.PrintWriter(new java.io.FileOutputStream(s));
for (int i=0;i<4;i++)
{
pw.println(x[i]+"");
}
pw.close();
}catch(Exception e)
{
System.out.println("Write file error:"+e.getMessage());
}
}
%>
<%
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)
{
count = getNumber(s);
count[choice]++;
setNumber(s,count);
}
response.sendRedirect("vote.jsp");
%>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -