Generate CSV in jsp without third party utility
There are lot of third party paid and free utility that generate CSV file in JSP/Java. but the problems are to hard to implement. and may utility first create CSV file in the server, so Server space will be consumed.
To overcome all the problem I have created listed below the code. You are free to use it in you project.
<%@ page import="java.util.ArrayList"%>
<%
response.setContentType("application/csv");
response.setHeader("content-disposition","filename=test.csv");
// the session.getAttribute("listResult") is containg of comma sepearte multiple lines as listed below
//aa,10,20,30
//bb,10,20,30
//cc,10,20,30
//dd,10,20,30
ArrayList<String> list = (ArrayList<String>)session.getAttribute("listResult");
out.println("<table border='1'>");
for(int i = 0; i < list.size(); i++) {
String myString = (String)list.get(i);
out.println(myString);
}
out.flush();
out.close();
%>
There are lot of third party paid and free utility that generate CSV file in JSP/Java. but the problems are to hard to implement. and may utility first create CSV file in the server, so Server space will be consumed.
To overcome all the problem I have created listed below the code. You are free to use it in you project.
<%@ page import="java.util.ArrayList"%>
<%
response.setContentType("application/csv");
response.setHeader("content-disposition","filename=test.csv");
// the session.getAttribute("listResult") is containg of comma sepearte multiple lines as listed below
//aa,10,20,30
//bb,10,20,30
//cc,10,20,30
//dd,10,20,30
ArrayList<String> list = (ArrayList<String>)session.getAttribute("listResult");
out.println("<table border='1'>");
for(int i = 0; i < list.size(); i++) {
String myString = (String)list.get(i);
out.println(myString);
}
out.flush();
out.close();
%>
0 comments:
Post a Comment