如何将数据库信息通过jee导出到文本文件并存在本地

具体实现这样一个功能:页面上有某些条件,填写完之后点击导出按钮,会弹出一个框,然后选择存放的目录,然后点击确定之后,系统会根据条件将查出的记录一条条地写到文本文件中并存放到指定的目录中。但是如果将用户输入的路径传到后台以及如何弹出对话框来交互,请指教!最好有示范性代码!谢谢!

你把参数提交给后台我这里是Servlet,然后根据参数取出你要的数据组装成字符串或者生成你需要的文档的文件流。输出到response.getOutputStream()就可以实现下载了。
下面是Servlet代码:
[code="java"]
OutputStream outputStream = null;
try {
response.setCharacterEncoding("UTF-8");
outputStream = new BufferedOutputStream(response.getOutputStream());

        String fileName = "fileName.txt";

        response.setContentType("application/data");

        response.setHeader("content-disposition", "attachment;filename=\""+ new String(fileName.getBytes(), response.getCharacterEncoding()) + "\"");//设置下载的时候弹出保存提示的文件名

        String temp="导出文件内容";           
        outputStream.write(temp.getBytes("UTF-8"));

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (outputStream != null) {
            try {
                outputStream.flush();
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

[/code]