Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

Better use a Servlet for this. Raw Java code doesn't belong in a JSP file, that's simply recipe for maintenance troublemaintenance trouble.

Better use a Servlet for this. Raw Java code doesn't belong in a JSP file, that's simply recipe for maintenance trouble.

Better use a Servlet for this. Raw Java code doesn't belong in a JSP file, that's simply recipe for maintenance trouble.

deleted 70 characters in body
Source Link
BalusC
  • 1.1m
  • 377
  • 3.7k
  • 3.6k
public static <T> void writeCsv (List<List<T>> csv, char separator, OutputStream output) throws IOException { BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output, "UTF-8")); for (List<T> row : csv) { StringBuilder line = new StringBuilder(); for (Iterator<T> iter = row.iterator(); iter.hasNext();) { String field = String.valueOf(iter.next()).replace("\"", "\"\""); if (field.indexOf(separator) > -1 || field.indexOf('"') > -1) { field = '"' + field + '"'; } linewriter.append(field); if (iter.hasNext()) { linewriter.append(separator); } } writer.write(line.toStringnewLine()); }  writer.newLineflush(); } } 
public static <T> void writeCsv (List<List<T>> csv, char separator, OutputStream output) throws IOException { BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output, "UTF-8")); for (List<T> row : csv) { StringBuilder line = new StringBuilder(); for (Iterator<T> iter = row.iterator(); iter.hasNext();) { String field = String.valueOf(iter.next()).replace("\"", "\"\""); if (field.indexOf(separator) > -1 || field.indexOf('"') > -1) { field = '"' + field + '"'; } line.append(field); if (iter.hasNext()) { line.append(separator); } } writer.write(line.toString()); writer.newLine(); } } 
public static <T> void writeCsv (List<List<T>> csv, char separator, OutputStream output) throws IOException { BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output, "UTF-8")); for (List<T> row : csv) { for (Iterator<T> iter = row.iterator(); iter.hasNext();) { String field = String.valueOf(iter.next()).replace("\"", "\"\""); if (field.indexOf(separator) > -1 || field.indexOf('"') > -1) { field = '"' + field + '"'; } writer.append(field); if (iter.hasNext()) { writer.append(separator); } } writer.newLine(); }  writer.flush(); } 
added 322 characters in body
Source Link
BalusC
  • 1.1m
  • 377
  • 3.7k
  • 3.6k

Better use a Servlet for this. Raw Java code doesn't belong in a JSP file, that's simply receiptrecipe for maintenance troublemaintenance trouble.

Map this servlet on something like /csv/* and invoke it as something like http://example.com/context/csv/filename.csv. That's basically all. The filename in the pathinfo is important because a certain webbrowser developed by a team in Redmond ignores the filename part of the Content-Disposition header and uses the last path part of the URL instead.

Better use a Servlet for this. Raw Java code doesn't belong in a JSP file, that's simply receipt for maintenance trouble.

Map this servlet on something like /csv/* and invoke it as something like http://example.com/context/csv/filename.csv. That's basically all.

Better use a Servlet for this. Raw Java code doesn't belong in a JSP file, that's simply recipe for maintenance trouble.

Map this servlet on something like /csv/* and invoke it as something like http://example.com/context/csv/filename.csv. That's basically all. The filename in the pathinfo is important because a certain webbrowser developed by a team in Redmond ignores the filename part of the Content-Disposition header and uses the last path part of the URL instead.

fixed content type
Source Link
BalusC
  • 1.1m
  • 377
  • 3.7k
  • 3.6k
Loading
deleted 26 characters in body; added 1 characters in body
Source Link
BalusC
  • 1.1m
  • 377
  • 3.7k
  • 3.6k
Loading
fix
Source Link
BalusC
  • 1.1m
  • 377
  • 3.7k
  • 3.6k
Loading
Source Link
BalusC
  • 1.1m
  • 377
  • 3.7k
  • 3.6k
Loading