简单实现jsp输出文件

 

代码
<%@ page import="java.io.OutputStream" %>
<%--
Created by IntelliJ IDEA.
User: czy
Date:
2010-3-31
Time:
23:20:32
To change
this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=gbk" language="java" %>
<html>
<head><title>Simple jsp page</title></head>
<body>
<%
String fileName
= "hello.txt";response.setContentType("text/plain");
response.setHeader(
"Location", fileName);
response.setHeader(
"Content-Disposition", "attachment; filename=" + fileName);
OutputStream outputStream
= response.getOutputStream();
String s
= "hello world";
byte[] buffer = new byte[1024];

outputStream.write(s.getBytes());
outputStream.flush();
outputStream.close();
out.clear();
out
=pageContext.pushBody();
%>
</body>
</html>

 

 

 

posted @ 2010-03-31 23:37  雪霁霜飞  阅读(1241)  评论(0编辑  收藏  举报