?????????Java????Excel
???????????? ???????[ 2015/9/22 13:53:14 ] ??????????????????? ???????
????Web????????????????????????????????excel????????????????????????е???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????£?????????????????????itRed ????it_red@sina.com ?????????http://www.cnblogs.com/itred GitHub?????http://github.com/itred
???????????????????????????????????????????Χ????????????????????????????????????JXL???excel???????????????????????????????????????????jsp???????ú?action???response??????excel????????ɡ?????????????????????????????????????????????????????????塢??????????????????????????jsp?????????????????????????????????????????????????????????????????????????????????????г???
????Demo 1:
?????????????????????????action?н???????session???????????У????????????????jsp??棬???????jsp???????????ContentType????????????httpЭ???response.ContentType ???????ContentType??????????????????Ч????????ContentType?text/html????????????????????
???????web?????????struts2?????jar???? ??????index.jsp?????????form????????????????????????????????????????????????????input?????????????action??index.jsp????????£?
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>????</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1??keyword2??keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<form action="getXls_excel" method="post">
<input type="submit" value="??" />
</form>
</body>
</html>
??????????action???ExcelAction????????£?
package com.red.action;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
/**
* jsp???????excel
* @author Red
*/
public class ExcelAction extends ActionSupport {
private static final long serialVersionUID = -3673769122296267756L;
protected HttpServletRequest request = ServletActionContext.getRequest();
protected HttpServletResponse response = ServletActionContext.getResponse();
public void getXls() throws IOException {
StringBuffer sb = new StringBuffer();
sb.append("<table><tr><td>???????</td><td>??????</td></tr>");
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");
for (String key : map.keySet()) {
sb.append("<tr><td>").append(key).append("</td><td>").append(map.get(key)).append("</td></tr>");
}
request.getSession().setAttribute("excel"?? sb.toString());
response.sendRedirect(request.getContextPath() + "/export.jsp");
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11