各位高手,请赐一个例子吧!!
将一些文本信息在JSP页面上保存到文件里面
如:"工aaaaaaaaaaaaaaaaaa"这些一些文本信息
保存到  /share/a.txt文件里面去!!

解决方案 »

  1.   

    String[] compileuris = new String[]{"../webapps/xxx/include/newCom.jsp","../webapps/xxx/include/newNews.jsp","../webapps/xxx/include/recomTele.jsp","../webapps/xxx/include/hotPlay.jsp"};
    for(int i = 0; i < sourceuris.length; i++){
    url = sourceuris[i];
    name = compileuris[i];// 这是生成的html文件名,如index.html.

    RequestDispatcher rd = request.getRequestDispatcher(url);
    final ByteArrayOutputStream os = new ByteArrayOutputStream();
    final ServletOutputStream stream = new ServletOutputStream() {
    public void write(byte[] data, int offset, int length) {
    os.write(data, offset, length);
    }
    public void write(int b) throws IOException {
    os.write(b);
    }
    };
    final PrintWriter pw = new PrintWriter(new OutputStreamWriter(os,
    Charset.forName("utf-8")));

    HttpServletResponse rep = new HttpServletResponseWrapper(response) {
    public ServletOutputStream getOutputStream() {
    return stream;
    }

    public PrintWriter getWriter() {
    return pw;
    }
    };
    rd.include(request, rep);
    pw.flush();
    FileOutputStream fos0 = new FileOutputStream(name); // 把jsp输出的内容写到xxx.html
    os.writeTo(fos0);
    fos0.close();
    os.close();