public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
{
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter(); Conn co = new Conn();
DBcon con = new DBcon(co.getcon());
ResultSet rs = null; response.reset();
response.setContentType("text/plain"); OutputStream output = null;
InputStream input = null;
try
{
rs = con.doSelect("select pic from aa where id=2");
if (rs.next())
{
input = rs.getBinaryStream("pic");
} String filenamedisplay = "test.txt";
filenamedisplay = URLEncoder.encode(filenamedisplay, "UTF-8");
response.addHeader("Content-Disposition",
"attachment;filename=" + filenamedisplay); output = response.getOutputStream();
byte[] b = new byte[1024];
int i = 0;
while ( (i = input.read(b)) > 0)
{
output.write(b, 0, i);
} output.flush();
}
catch (Exception e)
{
System.out.println("Error!");
e.printStackTrace();
}
finally
{
if (input!= null)
{
input.close();
// input= null;
}
if (output != null)
{
output.close();
//output = null;
}
} }
如题,请高手指教!
ServletException, IOException
{
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter(); Conn co = new Conn();
DBcon con = new DBcon(co.getcon());
ResultSet rs = null; response.reset();
response.setContentType("text/plain"); OutputStream output = null;
InputStream input = null;
try
{
rs = con.doSelect("select pic from aa where id=2");
if (rs.next())
{
input = rs.getBinaryStream("pic");
} String filenamedisplay = "test.txt";
filenamedisplay = URLEncoder.encode(filenamedisplay, "UTF-8");
response.addHeader("Content-Disposition",
"attachment;filename=" + filenamedisplay); output = response.getOutputStream();
byte[] b = new byte[1024];
int i = 0;
while ( (i = input.read(b)) > 0)
{
output.write(b, 0, i);
} output.flush();
}
catch (Exception e)
{
System.out.println("Error!");
e.printStackTrace();
}
finally
{
if (input!= null)
{
input.close();
// input= null;
}
if (output != null)
{
output.close();
//output = null;
}
} }
如题,请高手指教!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货