开发者

Manipulating CSV file via JSP page

I could really use some help on this one. I am being handed a CSV file that I need to modify and spit开发者_StackOverflow back out a new CSV file that will then be saved on the users local hard drive. The changes I need to make are pretty simple. Just add a break before each eMail address. I am pretty new with JSP (not quite a year) so any ideas would be helpful.

Thanks


... that operation would be best done in a Servlet instead.

...read the file ..

... parse it ...

... sample:

try {
BufferedReader in = new BufferedReader(new FileReader("infilename"));
String str;
while ((str = in.readLine()) != null) {
    process(str);
}
in.close();

} catch (IOException e) { }

taken from here


this can be complex in jsp but try this if possible.

1) take a responcemsg as string builder and append in that manner. String str = convertStreamToString(msg);

StringBuilder sb;
if(str!=null){
String[] rows = str.split("\n");
for(int i=0;i<rows.length;i++){
String[] cols = rows[i].split(",");
sb = new StringBuilder();
if(cols.length>=2)
name=cols[0];                       
name = name.substring(1,name.length()-1);                           
value = cols[1];                            
dif = cols[4];
System.out.println(dif);
sb.append("<b>"+name+"</b>").append(":").append(value).append(":");
    }                       
out.print(sb.toString());   
System.out.println(sb.toString());
}
out.flush();            
}

2) take that string in jsp and split the string in your manner and again appent that in CSV file

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜