- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试通过按钮生成 pdf,但我的问题是这种方法 JasperRunManager.runReportToPdfStream(reportStream,servletOutputStream, new HashMap<Object, Object>(), resultSetDataSource);
它不支持 Hashmap,它给出以下错误
The method runReportToPdfStream(InputStream, OutputStream, Map<String,Object>, Connection) in the type JasperRunManager is
not applicable for the arguments (InputStream, ServletOutputStream, HashMap<Object,Object>, JRResultSetDataSource)
它支持像Hashmap<String,Object>
这样的字符串参数生成 pdf 时出现以下错误
net.sf.jasperreports.engine.JRException: Error loading object from InputStream
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:219)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:632)
at net.sf.jasperreports.engine.JasperRunManager.runToPdfStream(JasperRunManager.java:428)
at net.sf.jasperreports.engine.JasperRunManager.runReportToPdfStream(JasperRunManager.java:849)
at com.p41.jasper.Jasper.doPost(Jasper.java:103)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:546)
at com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandlingStrategy.java:364)
at com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:154)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:410)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.p41.setting.FacesFilter.doFilter(FacesFilter.java:153)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.StreamCorruptedException: invalid stream header: 3C3F786D
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.<init>(Unknown Source)
at net.sf.jasperreports.engine.util.ContextClassLoaderObjectInputStream.<init>(ContextClassLoaderObjectInputStream.java:53)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:214)
小服务程序
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.HashMap;
import java.util.HashSet;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JasperRunManager;
public class Jasper extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Connection connection;
Statement statement;
ResultSet resultSet;
response.setContentType("text/html");
String si = request.getParameter("input");
ServletOutputStream servletOutputStream = response.getOutputStream();
byte[] bytes = null;
InputStream reportStream = getServletConfig().getServletContext().getResourceAsStream("WEB-INF/HR/Jasp.jasper");
System.out.println("Print" + si);
try {
System.out.println("Second print" + si);
String query = "SELECT Where Empno = '" + si + "' ";
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/schemedb?user=root&password=root");
statement = connection.createStatement();
resultSet = statement.executeQuery(query);
JRResultSetDataSource resultSetDataSource = new JRResultSetDataSource(resultSet);
response.setContentType("application/pdf");
servletOutputStream.flush();
servletOutputStream.close();
System.out.println("print" + reportStream);
System.out.println("print" + servletOutputStream);
System.out.println("print" + resultSetDataSource);
JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream, new HashMap<Object, Object>(), resultSetDataSource);
resultSet.close();
statement.close();
connection.close();
response.setContentType("application/pdf");
servletOutputStream.flush();
servletOutputStream.close();
} catch (Exception e) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
e.printStackTrace(printWriter);
response.setContentType("text/plain");
response.getOutputStream().print(stringWriter.toString());
}
}
}
最佳答案
解决方案是我删除了 Run Report pdf 流并使用方法作为 exportReport 到 pdf 流
JasperRunManager.runReportToPdfStream(reportStream,servletOutputStream, new HashMap<Object, Object>(), resultSetDataSource);
编码:-
InputStream reportStream = getServletConfig().getServletContext().getResourceAsStream("WEB-INF/HR/Jasp.jrxml");
ByteArrayOutputStream baos =new ByteArrayOutputStream();
response.setContentType("application/pdf");
JasperDesign design = JRXmlLoader.load(reportStream);
JasperReport report = JasperCompileManager.compileReport(design);
JRResultSetDataSource jasperReports = new JRResultSetDataSource(rs);
JasperPrint print = JasperFillManager.fillReport(report, new HashMap(), jasperReports);
net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfStream(print,baos);
response.setContentLength(baos.size());
ServletOutputStream out1 = response.getOutputStream();
baos.writeTo(out1);
out1.flush();
rs.close();
st.close();
conn.close();
关于java - 在调用 JasperRunManager.runReportToPdfStream 期间获取 "Error loading object from InputStream"异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20040562/
我在一个类中有两个方法: private static InputStream getSongStream(String ip, String id){ try { U
我创建了一个扩展 InputStream 的新类并且必须 @Override read()。我正在尝试使用方法 read(int b),但是当我使用它时,它会转到方法read() 和我不能使用参数,我
我正在尝试编写一个函数,该函数将接受带有压缩文件数据的 InputStream 并返回另一个带有解压缩数据的 InputStream。 压缩后的文件将只包含一个文件,因此不需要创建目录等... 我尝试
我想知道是否有任何理想的方式可以将多个 InputStream 链接到 Java(或 Scala)中的一个连续 InputStream 中。 我需要它来解析我从 FTP 服务器通过网络加载的平面文件。
我想做的是:打开大文件的 InputStream,按 10MB block 读取它,上传一个 block ,读取下一个 block 。 val chunkCount = Math.ceil(total
我不知道怎么理解: { if (inputStream **!= null**) { inputStream.close(); 来自那个例子: public c
我想知道 InputStream 是否为空,但不使用 read() 方法。有没有办法不读取就知道它是否为空? 最佳答案 不,你不能。 InputStream 设计用于处理远程资源,因此在实际读取它之前
我制作了一个蓝牙输入流监听器,只需询问 if(InputStream.isAvailable > 0) 即可检查是否有传入数据,然后创建一个循环将传入数据存储到 int[] 直到没有更多并且它工作完美
这是我的代码流程,文件内容丢失,我认为可能是 IOUtils.toByteArray() 行有问题,请指导这里实际出了什么问题。 文件内容丢失: InputStream stream = someCl
我从 HTTP 请求的响应开始: InputStream responseInputStream = response.getEntityInputStream() 我需要对该响应进行 gzip 压缩
用户将一个大文件上传到我的网站,我想对该文件进行 gzip 压缩并将其存储在 blob 中。所以我有一个未压缩的 InputStream,而 blob 需要一个 InputStream。我知道如何使用
我调用了一个返回压缩文件的服务。我从响应中将数据作为 InputStream(由 javax.activation.DataHandler.getInputStream(); 提供)提供。 我想做的是
我正在尝试压缩一个 InputStream 并返回一个 InputStream: public InputStream compress (InputStream in){ // Read "in
我最近在 Kotlin 中看到了将 InputStream 的全部内容读入 String 的代码,例如: // input is of type InputStream val baos = Byte
我正在尝试使用以下代码从 IHTTPSession.getInputStream() 读取 InputStream,但它每次都给出 Socket TimeOut Exception。 private
如 How to use Jersey interceptors to get request body 中所述,我正在修改 ContainerRequestFilter 中的 EntityInput
我正在编写一个需要与蓝牙 2.1 设备交换数据的应用程序。我已经做过好几次了,但这次发生了一些奇怪的事情。 Log.d("TAG", "connectToDevice"); if(ma
我只是在犹豫这是好主意还是坏主意: InputStreamReader in = new InputStreamReader(socket.getInputStream()); BufferedRea
我正在开发一个 Android 应用程序,它的 View 包含多个图库。图库的内容(位图)是来自 Internet 的红色。 对于第一个画廊,一切正常,但是当尝试下载第二个画廊的第一张图片时,Bitm
在Dart中,我想读取BMP,所以可能是BIG文件。 我这样做是这样的: var inputStream = imageFile.openInputStream(); inputStream.onDa
我是一名优秀的程序员,十分优秀!