求解释。
public HashMap<String, Object> outEmployee(InvokeContext ctx){
String result = "";
HashMap<String, Object> resultMap = new HashMap<String, Object>();
//创建一个空白的WorkBook
HSSFWorkbook wb = new HSSFWorkbook();
//基于上面的wb创建属于WorkBook的Sheet
HSSFSheet st = wb.createSheet("职工信息");
//基于上面的st创建Sheet的Row
HSSFRow row = st.createRow(0);//从数据库中查询一共有多少条职工信息
//基于上面的Row创建Row的Cell
HSSFCell cell = row.createCell(0);
//为Cell填充值
HSSFCellStyle style = wb.createCellStyle();
Font font = wb.createFont();
//font.setFontHeightInPoints((short)24); //字体大小
//font.setFontName("楷体");
font.setBoldweight(Font.BOLDWEIGHT_BOLD); //粗体
font.setColor(HSSFColor.RED.index); //红色字体
style.setFont(font);
cell.setCellValue("序号");
HSSFCell cell1 = row.createCell(1);
cell1.setCellType(HSSFCell.CELL_TYPE_STRING);
cell1.setCellValue("职工编号");
cell1.setCellStyle(style);
HSSFCell cell2 = row.createCell(2);
cell2.setCellValue("职工姓名");
cell2.setCellStyle(style);
HSSFCell cell3 = row.createCell(3);
cell3.setCellValue("性别");
cell3.setCellStyle(style);
HSSFCell cell4 = row.createCell(4);
cell4.setCellValue("单位名称");
cell4.setCellStyle(style);
HSSFCell cell5 = row.createCell(5);
cell5.setCellValue("email");
HSSFCell cell6 = row.createCell(6);
cell6.setCellType(HSSFCell.CELL_TYPE_STRING);
cell6.setCellValue("电话");
try {
List<Employee> list = this.daofac.getEmployeeDao().getAllEmployees();
for (int i = 1; i <= list.size(); i++) {
Employee emp = list.get(i-1);
HSSFRow rowi = st.createRow(i);
for (int j = 0; j < 7; j++) {
if(j==0){
HSSFCell cellj = rowi.createCell(j);
cellj.setCellValue(i);
}
if(j==1){
HSSFCell cellj = rowi.createCell(j);
cellj.setCellValue(emp.getEmpId());
}
if(j==2){
HSSFCell cellj = rowi.createCell(j);
cellj.setCellValue(emp.getEmpName());
}
if(j==3){
HSSFCell cellj = rowi.createCell(j);
if(emp.getSex()=="1" || emp.getSex().equals("1"))
cellj.setCellValue("男");
else
cellj.setCellValue("女");
}
if(j==4){
HSSFCell cellj = rowi.createCell(j);
cellj.setCellValue(emp.getDeptId());
}
if(j==5){
HSSFCell cellj = rowi.createCell(j);
cellj.setCellValue(emp.getEmail());
}
if(j==6){
HSSFCell cellj = rowi.createCell(j);
cellj.setCellType(HSSFCell.CELL_TYPE_STRING);
cellj.setCellValue(emp.getTelephone());
}
}
}
//创建一个文件输出流,指定输出到C盘根目录下
FileOutputStream fos = new FileOutputStream("c:/upload/temp/employeeInfoTemp.xls");
//把WorkBook写到流里
wb.write(fos);
//刷新
fos.flush();
//手动关闭流
fos.close();
//获取文件
File file = new File("c:/upload/temp/employeeInfoTemp.xls");
//下载文件
//定义文件输入流对象
FileInputStream fileInputStream = null;
// 读取文件
fileInputStream = new FileInputStream(file);
//设置浏响应的文件类型为.xls
HttpServletResponse resp = ServletActionContext.getResponse();
//定义文件输出流对象
OutputStream out = resp.getOutputStream();
resp.setContentType("application/x-msdownload");
//设置表头
resp.setHeader("Content-Disposition", "attachment;fileName=" + new String( "employeeInfoTemp.xls".getBytes("gb2312"), "ISO8859-1" ) );
if (fileInputStream != null) {
//文件大小
int filelen = fileInputStream.available();
//以字节为单位读取文件,常用于读二进制文件
byte a[] = new byte[filelen];
//输入流读取
fileInputStream.read(a);
//输出流读取
out.write(a);
}
//输入流关闭
fileInputStream.close();
//输出流关闭
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
result += "导出失败!";
resultMap.put("result", result);
} catch (IOException e) {
e.printStackTrace();
result += "导出失败!";
resultMap.put("result", result);
}
if(result.equals("") || result==""){
result = "导出成功!";
resultMap.put("result", result);
}
return resultMap;
}
}
这个导出的代码,导出有成功但是有报错误,不知道如解决所以请NN们帮忙看下如果觉得分数不够可以在追加分数。
错误如下08:46:00,651 WARN log:? - Committed before 500 Unable to show problem report: java.lang.IllegalStateException: STREAM
08:46:00,667 ERROR log:? - /employeemgr!output.do
java.lang.IllegalStateException: Committed
at org.mortbay.jetty.Response.resetBuffer(Response.java:994)
at org.mortbay.jetty.Response.sendError(Response.java:240)
at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:118)
at org.springframework.security.context.HttpSessionContextIntegrationFilter$OnRedirectUpdateSessionResponseWrapper.sendError(HttpSessionContextIntegrationFilter.java:498)
at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:752)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:505)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1115)
[解决办法]
at com.pfmg.config.ParamEncFilter.doFilter(ParamEncFilter.java:36)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1115)
at org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:102)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1115)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1115)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:361)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:417)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:534)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:864)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:533)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:207)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:403)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:522)
[解决办法]
Committed before 500 Unable to show problem report: java.lang.IllegalStateException: STREAM
08:46:00,667 ERROR log:? - /employeemgr!output.do
你先搜下这个错误是怎么回事
[解决办法]
还真没遇到过,建议你走个断点,一步步往下看,地位到具体的代码行,然后仔细琢磨一下。
[解决办法]
在非法或不适当的时间调用方法时产生的信号。换句话说,即 Java 环境或 Java 应用程序没有处于请求操作所要求的适当状态下
employeemgr!output.do这个的请求过程是什么样子的
[解决办法]