有个关于客户端导出txt文件的问题!

项目中需要导出一个txt文件
jsp中是这样

 

 

  <%ImportTxt imt = new ImportTxt();
        String filename = imt.buildFileName("","1234",FileType.TXT);
        String res = imt.getSQL("eee","fdsaf");
        System.out.print(res);      
        imt.importTxt(response,res,filename);
     %>

 ImportTxt.java

 

/**
     * 在客户端生成文件。
     * 
     * @param response
     * @param content
     * @param filename
     * @return boolean 
     */
    public boolean importTxt(HttpServletResponse response,String content,String filename) {
        boolean res = true ;
        
        response.addHeader("Content-Disposition",
                "attachment; filename=" + filename);
        response.setContentType("application/octet-stream");
        try {
            response.getWriter().write(content);
            response.flushBuffer();
        } catch (IOException e) {
            res = false ;
            e.printStackTrace();
        }
        return res ;}

 

生成一个

<html>
  <head>
    <base href="http://172.19.74.100:7001/WebRoot/">
    
    <title>My JSP 'improtTxt.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    

  </head>
  
  <body>
    1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5,

  
  </body>
</html>

 

 文件,我的目的是生成一个<body>之间的内容就OK了!

 

哪位点一下!!!

 

 

 

 

在 response.getWriter().write(content); 之前加上

int indexBegin = content.indexOf("

");
int indexEnd = content.indexOf("");
if ((indexBegin>-1)&&(indexEnd>-1)){ //, 都存在
content = content.substring(indexBegin,indexEnd);

}else if ((indexBegin>-1)&&(indexEnd==-1)){ //存在,不存在
content = content.substring(indexBegin);
}else if ((indexBegin==-1)&&(indexEnd>-1)){ //不存在, 存在
content = content.substring(0,indexEnd);
}

使用substring截取content

之间的内容