This issue can be discussed in two parts: 1. CSV file format 2. Output CSV files to the client through JSP The first question is discussed in a simple way. It can be considered that each field is included and reused with "" and separated by numbers. For example: "A", "B", "C" "D", "E", "F" Now we have the contents of the CSV file. Let's see how to output it to the client. A work und is to write the CSV content to a temporary file, and then ask the client to download the temporary file. However, the simplest method is to directly output the following content to the client: CSV. jsp "A", "B", "C" "D", "E", "F" In this case, the information is output to the client. However, it is estimated that the current situation will not meet the requirements of the landlord, because the browser handles the information itself, rather than handing it over to excel for processing. In order for the browser to handle the processing right, we need to add some information in the header of the JSP to tell the browser that you do not have to worry about this information, hand it over to other appropriate programs (Excel for CSV) for processing. First, tell it "The following information is M $, not html ": <% @ Page Language = "Java" contenttype = "application/MS-excel" %> Then upload the file test.csv. <% Response. setheader ("content-disposition", "filename=test.xls"); %> Finally, the content of the file: "A", "B", "C" "D", "E", "F" This is the full text. <% @ Page Language = "Java" contenttype = "application/MS-excel" %> <% Response. setheader ("content-disposition", "filename=test.xls"); %> "A", "B", "C" "D", "E", "F" The landlord can replace ABCD with something you can find from Javabean. When I access this page again, I will prompt you to open or save it. It should be the result that the landlord wants. |