有一个index.jsp页面include文件aaa.txt.1、index.jsp里有个String变量:strnr
2、aaa.txt里的内容如下:
aaaa
bbbb
cccc
dddd
eeee
如何把aaa.txt内容传给strnr变量.
先谢谢大家!

解决方案 »

  1.   

    在jsp中用java代码读取该文件内容
      

  2.   

    输入读取 IO流啊
    兄弟,这个可以实现的1.
    private void show() throws Exception{
    InputStreamReader a=new InputStreamReader(System.in);
    BufferedReader b=new BufferedReader(a);
    System.out.println ("请输入用户名:");
    String name=b.readLine();
    if (name.equals("admin")){
    System.out.println ("用户名正确!");
    }else if (name.length()==0){
    System.out.println ("用户名不能为空!");
    }else{
    System.out.println ("你输入的用户名不正确!");
    }

    System.out.println ("请输入密码:");
    String pw=b.readLine();

    if (pw.equals("123456")){
    System.out.println ("密码正确!\n登陆成功!");
    }else if (pw.length()==0){
    System.out.println ("密码不能为空!");
    }else{
    System.out.println ("你输入的密码不正确!");
    }

    FileWriter f= new FileWriter("e:\\name.txt");
    BufferedWriter w=new BufferedWriter(f);
    w.write("用户名:"+name);
    w.newLine();
    w.write("密码:"+pw);

    b.close();
    w.close();
    }

    public static void main(String []args) throws Exception
        {
            new Z8_4().show();
        }2.
    public void Reader_b(String str) throws Exception{
            int i ;
            BufferedReader b = new BufferedReader(new FileReader(new File(str)));
            
            do{
             i = b.read();
                if(i != -1){
                    System.out.print(Character.toUpperCase((char)i));
                }
                     
            }while(i != -1);
    System.out.println ();
            b.close();
        } public static void main(String []args) throws Exception
        {
            Z8_3 s=new Z8_3();
            s.Reader_b("d:\\1.txt");
        }2个小例子,你看看
    希望对你有帮助哦
    ^_*
      

  3.   

    呵呵,谢谢楼上两位,我知道用读取文件的方法可以实现,但想省事,直接用include来处理.实在不行也只能用读文件的方法了
      

  4.   

    <jsp:include>
    <param name="strnr" value=""/>
    </jsp:include>
    txt文件去处理一下