别人能够访问你的vote.txt 吗?
不知道vote.txt 这个文件你放到哪里了,我知道放到WEB-INF下是安全的,你可以放到那里面去。

解决方案 »

  1.   

    同意楼上说的,你可以用httpRequest.getContextPath()得到webapp在服务器上的物理路径
      

  2.   

    你用的是什么Web服务器?你可以把这个vote.txt文件放到web站点以外的地方,然后用文件流的方式访问它,这样别人基本上通过Web是没有办法篡改它了。
      

  3.   

    我用的是resin,vote.txt如何放至呀.
    看源码
    <%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
    <%@ page import="java.util.*"%>
    <%@ page import="java.lang.*"%>
    <%@ page import="java.io.*"%>
    <jsp:useBean id="vote" scope="request" class="vote.vote"/>
    <%
    String vote1=request.getParameter("lang");
    vote.n=4;
    vote.filePath="vote.txt";
    vote.createFile();
    vote.readFile();
    if(vote1.compareTo("0")==0)
    vote.voteNum[0]++;
    if(vote1.compareTo("1")==0)
    vote.voteNum[1]++;
    if(vote1.compareTo("2")==0)
    vote.voteNum[2]++;
    if(vote1.compareTo("3")==0)
    vote.voteNum[3]++;
    vote.writeFile();
    %>
    <script language="javascript">
     alert("感谢你投了宝贵的一票");
     self.location="index.jsp";
    </script>
      

  4.   

    package vote;
    import java.io.*;
    import java.util.*;
    public class vote extends Object
    {
     public String filePath="";
     public int n;
     private File voteFile;
     private BufferedReader fileRead;
     private PrintWriter fileWrite;
     public String systemMessage="";
     private String voteStr[]=new String[10];
     public int voteNum[]=new int[10];
     public void createFile()
            throws FileNotFoundException
    {
             voteFile=new File(filePath);
                if(!voteFile.exists())
                {
                 fileWrite=new PrintWriter(new FileOutputStream(filePath));
                 for(int i=0;i<n;i++) fileWrite.println("0");
                 fileWrite.close();
                 }
    }
    public void writeFile()
           throws FileNotFoundException
            {
            fileWrite=new PrintWriter(new FileOutputStream(filePath));
            for(int i=0;i<n;i++)
            {
            fileWrite.println(voteNum[i]);
            }
                 fileWrite.close();
               }
    public void readFile()
                throws FileNotFoundException
                     {
                     fileRead=new BufferedReader(new FileReader(filePath));
                     for(int i=0;i<n;i++)
                     {
                     try
                     {voteStr[i]=fileRead.readLine();
                     }
                     catch(IOException f)
                     {
                     voteStr[i]="0";}
                     voteNum[i]=Integer.parseInt(voteStr[i]);
                     }
                     try
                     {      
                     fileRead.close();
                     }
                     catch(IOException d)
                     {
                     systemMessage=d.toString();
                     }
                     }
    }
      

  5.   

    vote.filePath="vote.txt";//放在当前目录下了。
    但是,通过web如何能向vote.txt写入数据?