- 首页 > it技术 > >
js部分:
var jsonstr=getSearchSel(os);
var str = "";
//传参数
for(var i in jsonstr){
if(jsonstr[i]!=""){
str += i+"="+jsonstr[i]+"&";
}
}
str = str.substr(0, str.length - 1);
var url = "/QAdevices/ExcelServlet?" + str;
window.open(url);
java端:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
StringBuilder jsonstr = new StringBuilder();
//转化成json
jsonstr.append("{");
String reqstr = request.getQueryString();
//获取请求参数
if(!"".equals(reqstr) &&reqstr !=null){String [] stringArr= reqstr.split("&");
for(int i = 0;
i> searchlist = ServerInit.managerAction.searchDeviceInfoByConditions3(jsonstr.toString());
if(searchlist!=null){
HSSFWorkbook wb = createExcel(searchlist);
try{ //写入浏览器
response.setHeader("content-disposition", "attachment;
filename=" + URLEncoder.encode(filename, "UTF-8"));
OutputStream outputStream=response.getOutputStream();
wb.write(outputStream);
outputStream.flush();
outputStream.close();
}catch(Exception e){
logger.error("Exception",e);
}
}
}
/**
*返回excel表生成的路径
*参数
*os,devicestatue,peopleId
* @return excel表的服务器存储地址
* */
public String getExcelPath() {
//String str = this.getServletContext().getRealPath("/WEB-INF");
List
【java 生成excel表传给前端下载】
推荐阅读