日期:2014-05-17 浏览次数:21331 次
<bean id="jasperReportsViewResolver" class="org.springframework.web.servlet.view.jasperreports.JasperReportsViewResolver"> <property name="order" value="0"></property> <property name="viewClass" value="org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView"/> <property name="prefix" value="/WEB-INF/jasper/"/> <property name="suffix" value=".jrxml"/> <property name="viewNames" value="rpt*"/> <property name="jdbcDataSource" ref="dataSource"/> <property name="exporterParameters"> <map> <!-- Force bei allen UTF-8 --> <entry key="net.sf.jasperreports.engine.JRExporterParameter.CHARACTER_ENCODING"> <value>utf-8</value> </entry> <!-- keine Images als Platzhalter in HTML-Seiten , vermeidet nullpx-Problem --> <entry key="net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN"> <value type="java.lang.Boolean">false</value> </entry> <entry key="net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IMAGES_URI"> <value type="java.lang.String">/html/image.jsp?image=</value> </entry> <entry key="net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IMAGES_DIR_NAME"> <value type="java.lang.String">D:\\work\\***\\web\\tmp</value> </entry> <entry key="net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR"> <value type="java.lang.String">true</value> </entry> </map> </property> </bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/"></property> <property name="suffix" value=".jsp"></property> </bean>
<%@ page import="java.io.*" %> <% String imagePath = System.getProperty("***") + "/web/tmp"; String name = request.getParameter("image"); imagePath += "/" + name; response.reset(); OutputStream output = response.getOutputStream();// 得到输出流 response.setContentType("image/png"); // ServletContext context = getServletContext();// 得到背景对象 File f = new File(imagePath); InputStream imageIn = new FileInputStream(f); BufferedInputStream bis = new BufferedInputStream(imageIn);// 输入缓冲流 BufferedOutputStream bos = new BufferedOutputStream(output);// 输出缓冲流 byte data[] = new byte[4096];// 缓冲字节数 int size = 0; size = bis.read(data); while (size != -1) { bos.write(data, 0, size); size = bis.read(data); } bis.close(); bos.flush();// 清空输出缓冲流 bos.close(); output.close(); %>