<%
response.setHeader("Content-Disposition", "attachment;filename=filename.doc");
%>
<%
response.setHeader("Content-Disposition", "attachment;filename=<%=docName%>.doc");
%>
package yourpackage;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import oracle.sql.*;
import beans.yourbeanpackage. getBlobBean;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class GetBlobServlet1 extends HttpServlet {
//设置输出内容类型,这个设置很重要,否则客户端浏览器不能识别输出内容,导致弹出下载的对话框。
private static final String CONTENT_TYPE = "application/msword;charset=gb2312";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
perform(request,response);
}
public void perform(HttpServletRequest request, HttpServletResponse response){
try{
//该类功能是从oracle哭中取出blob实体
getBlobBean getBlob=new getBlobBean();
OutputStream sos = response.getOutputStream();
getBlob.connFunction();
oracle.sql.BLOB blob=getBlob.getBlob("cehui");
//输出word文档
if(blob!=null){
InputStream pi = blob.getBinaryStream();
int blobsize =(int)blob.length();
byte[] blobbytes = new byte[blobsize];
int bytesRead = 0;
while ((bytesRead = pi.read(blobbytes)) != -1) {
sos.write(blobbytes, 0, bytesRead);
}
pi.close();
sos.flush();
sos.close();
}
getBlob.dropConnFunction();
}catch(Exception e){
System.out.println(e.toString());
}
}
//Clean up resources
public void destroy() {
}
}
<%@ page contentType="application/vnd.ms-excel; charset=gb2312" %>
<%
response.setHeader("Content-Disposition", "attachment;filename=20050304.xls");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>生成</title>
</head>
<body>
生成例子excel 。 用WORD排版面,倒出HTML 把代码拷贝到网页里,然后这个JSP页面打印你就随心所欲的控制了。
</body>
</html>
<%@
page import="java.io.*,java.awt.Color,com.lowagie.text.*,com.lowagie.text.pdf.*"%>
<%
response.setContentType( "application/pdf" );
Document document = new Document();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
PdfWriter writer=PdfWriter.getInstance( document, buffer );
document.open();
document.add(new Paragraph("Hello World"));
document.close();
DataOutput output = new DataOutputStream( response.getOutputStream() );
byte[] bytes = buffer.toByteArray();
response.setContentLength(bytes.length);
for( int i = 0; i < bytes.length; i++ ) { output.writeByte( bytes[i] ); }
%>
<%@ page import ="com.lowagie.text.*,com.lowagie.text.pdf.*, java.io.*"%>
<%
String filename = "D://test//111111.pdf" ;
Document document = new Document(PageSize.A4);
ServletOutputStream out1 = response.getOutputStream();
try{
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename) );
document.open();
document.add(new Paragraph("Hello World中文支持"));
document.close();
}
catch(Exception e){}
%>
BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
Font FontChinese = new Font(bfChinese, 12, Font.NORMAL);
String title = "我爱喝咖啡"; Paragraph t = new Paragraph(title, FontChinese); doc.add(t);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有