???????????????????jsp??棬????????excel???????????????£?
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page contentType="application/msexcel"%>
<%
response.setContentType("application/msexcel;charset=UTF-8");
response.setHeader("Content-disposition"?? "attachment; filename=test.xls");
%>
<html>
<head>
<title>Excel</title>
</head>
<body>
<%
String str = new String(session.getAttribute("excel").toString());
out.print(str);
%>
</body>
</html>
??????????????????????????????????????????б???????????????????????????????response.setContentType("application/msexcel;charset=UTF-8");?е??????????GBK????GB18030????????????С?
????????????????Ч?????£?

????Demo2??
?????????????????????????????????????????????????????????????????????????ContentType????????action?У???????????jsp??????
????????JXL??jar????Action???
package com.red.action;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jxl.Workbook;
import jxl.format.UnderlineStyle;
import jxl.write.Colour;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
/**
* ?????????????Excel
* @author Red
*/
public class WriteExcelAction extends ActionSupport {
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
public void writeExcel() throws RowsExceededException?? WriteException?? IOException {
OutputStream os = response.getOutputStream();// ????????
response.reset();// ????????
response.setHeader("Content-disposition"?? "attachment; filename=testRed.xls");// ?趨???????
response.setContentType("application/msexcel");// ???????????
WritableWorkbook wbook = Workbook.createWorkbook(os); // ????excel???
String tmptitle = "????????"; // ????
WritableSheet wsheet = wbook.createSheet(tmptitle?? 0); // sheet????
// ????excel????
WritableFont wfont = new WritableFont(WritableFont.ARIAL?? 16?? WritableFont.BOLD?? false??
UnderlineStyle.NO_UNDERLINE?? Colour.BLACK);
WritableCellFormat wcfFC = new WritableCellFormat(wfont);
wcfFC.setBackground(Colour.AQUA);
wsheet.addCell(new Label(1?? 0?? tmptitle?? wcfFC));
wfont = new jxl.write.WritableFont(WritableFont.ARIAL?? 14?? WritableFont.BOLD?? false??
UnderlineStyle.NO_UNDERLINE?? Colour.BLACK);
wcfFC = new WritableCellFormat(wfont);
// ???????????????
wsheet.addCell(new Label(0?? 2?? "????"));
wsheet.addCell(new Label(1?? 2?? "????"));
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Map<String?? String> map = new HashMap<String?? String>();
map.put("Red1"?? "it_red@sina.com");
map.put("Red2"?? "it_red@sohu.com");
map.put("Red3"?? "it_red@163.com");
int count = 0;
for (String key : map.keySet()) {
wsheet.addCell(new Label(0?? count + 3?? key));
wsheet.addCell(new Label(1?? count + 3?? map.get(key)));
count++;
}
// ???????????????
wbook.write(); // д?????
wbook.close();
os.close(); // ?????
}
}
???????Ч?????£?

?????????????????Demo????????????excel???????????????????????????????????????????????excel?????????????????????????????????????????????????????????????l??????????????????????????????????????????excel?????????????????????Щ?????????