今天用struts做jxl导出为excel文件时,报出个异常,但是文件还是导出成功了.百思不得其解,就google了下,找到了一下两种方式:
1.
out.clear();
out = pageContext.pushBody();
在使用完输出流后加上这样两句,但是我用的是以下方式:
jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(response.getOutputStream());
jxl.write.WritableSheet ws = wwb.createSheet(sheetName, 0);
//xls 格式
jxl.write.WritableFont wfc = new jxl.write.WritableFont(WritableFont.ARIAL,
10, WritableFont.NO_BOLD, false, jxl.format.UnderlineStyle.NO_UNDERLINE,
jxl.format.Colour.BLACK);
jxl.write.WritableCellFormat wcfFC = new jxl.write.WritableCellFormat(wfc);
//xls 格式
jxl.write.WritableFont ww = new jxl.write.WritableFont(WritableFont.TAHOMA, 11, WritableFont.BOLD, false, jxl.format.UnderlineStyle.NO_UNDERLINE);
jxl.write.WritableCellFormat wwf = new jxl.write.WritableCellFormat(ww);
List<String> list = new ArrayList<String>(); //title
根本的得不到out对象,问题的关键是out对象调用的response.getWriter()和response.getOutputStream()相冲突
2.最简单的一个解决办法不要返回ActionForward对象,return null就ok了
分享到:
相关推荐
在Java Web开发中,"getOutputStream() has already been called for this response" 是一个常见的错误,通常出现在使用Servlet或JSP时。这个错误意味着在HTTP响应中,`getOutputStream()`已经被调用,然后尝试再次...
在使用Tomcat 6服务器部署和运行Java Server Pages (JSP) 时,可能会遇到一个特定的异常:“getOutputStream() has already been called for this response”。该异常发生在尝试向响应对象中写入数据时,已经调用了...
纠结了半天的 java.lang.IllegalStateException: getOutputStream() has already。这个问题困扰了半天,在网上查阅了大量资料 出这个错误一般就是下面2个.....
验证码出现getOutputStream() has already been called for this response错误解决
解决了getOutputStream() has already been called for this response. 并将产生验证码的逻辑从JSP页面中分离出来,单独写了一个类 便于重用。
"Cannot forward after response has been committed" 是一个在Java Web开发中常见的错误,通常与Servlet、Filter或控制器逻辑有关。这个错误表明服务器已经完成了对HTTP响应的处理,并将其发送到客户端,然后试图...
`getOutputStream()` 方法就是从中获取一个输出流,这个流将用于向客户端发送响应内容。 `ServletOutputStream` 实例化后,我们可以通过调用它的`write()` 方法来写入字节数据。例如,如果我们在一个Servlet中想要...
标题 "java.lang.IllegalStateException: OutputStream already obtain" 涉及到的是Java编程中的一个常见错误,特别是当处理I/O流时。这个异常通常在尝试获取已经存在的OutputStream实例时抛出,表明该输出流已经被...
Returns a boolean indicating whether the named response header has already been set. contextDestroyed(ServletContextEvent) - Method in interface javax.servlet.ServletContextListener Notification ...
try (OutputStream os = connection.getOutputStream()) { BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8)); writer.write(getPostDataString(params)); ...
在合适的时机调用`BluetoothSocket.getOutputStream()`获取输出流,然后使用`OutputStream.write()`发送命令。由于描述中提到的数据是16进制格式,发送前需要将字符串转换成字节数组。 5. **接收蓝牙数据**: 同样...
EasyExcel.write(response.getOutputStream(), Student.class).sheet("学生信息").doWrite(students); } ``` 以上就是Spring Boot结合EasyExcel实现Excel导入导出的基本步骤。EasyExcel还支持更多高级功能,如...
* This method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server ...
DataOutputStream outToClient = new DataOutputStream(connectionSocket[i].getOutputStream()); outToClient.writeBytes("UNIX>Ntalk " + inet.getHostAddress() + '\n'); outToClient.writeBytes("Server:Red_...
数据的传输是通过`Socket`类提供的`getInputStream()`和`getOutputStream()`方法来实现的。这两个方法分别返回输入流和输出流,它们用于读取和发送数据。通常,我们会使用`BufferedReader`和`PrintWriter`对输入流和...
**Data Integrity**: Ensures that the data has not been tampered with during transmission. - C. **Confidentiality**: Ensures that the data is not disclosed to unauthorized parties. - A. **...
getWriter() 和Response.getOutputStream冲突
在本文中,我们将深入探讨如何使用Microsoft Foundation Class (MFC) 库在Visual C++ 6.0环境下实现JPEG图像的读取。MFC是微软为Windows应用程序开发提供的一组C++类库,它简化了Windows API的使用,使得开发者能够...