<% @ Page contenttype = "text/html; charset = GBK" %>
<% @ Page autoflush = "false" %>
<% @ Page import = "Java. SQL. *" %>
<% @ Page import = "Java. Io. *" %>
<% @ Page import = "Java. util. *" %>
<% @ Page import = "Java. AWT. *" %>
<% @ Page import = "Java. AWT. image. *" %>
<% @ Page import = "com.sun.image.codec.jpeg. *" %>
<% @ Page import = "com.sun.image.codec.jpeg. *" %>
<%!
Public static string getcontenttype (string pextfilename) // obtain the extension by gisoracle {
String pext = pextfilename. tolowercase ();
If (pext. Equals (". xls "))
{
Return "application/vnd. MS-excel ";
}
If (pext. Equals (". Doc "))
{
Return "application/MSWord ";
}
If (pext. Equals (". txt "))
{
Return "text/plain ";
}
If (pext. Equals (". pdf "))
{
Return "application/pdf ";
}
If (pext. Equals (". jpg") | pext. Equals (". jpeg "))
{
Return "image/JPEG ";
}
If (pext. Equals (". ppt "))
{
Return "application/vnd. MS-PowerPoint ";
}
If (pext. Equals (". GIF "))
{
Return "image/GIF ";
}
Return "text/html ";
}
%>
<%
String filename = request. getparameter ("FILENAME ");
File downfile = new file (filename );
String fileext = filetings. getfiletype (downfile );
System. Out. println ("fileext =" + fileext );
String contenttype1 = getcontenttype (fileext );
System. Out. println ("contenttype1 =" + contenttype1 );
Try {
Out. Clear ();
Response. setcontenttype (contenttype1 );
Filename = new string (filename. getbytes ("GBK"), "ISO-8859-1 ");
Response. setheader ("content-disposition", "attachment; filename =" + downfile. getname ());
Response. addheader ("cache-control", "No-Cache ");
Inputstream blobstream = new fileinputstream (downfile );
Servletoutputstream outstream = response. getoutputstream ();
Byte [] buffer = new byte [10*1024];
Int nbytes = 0;
While (nbytes = blobstream. Read (buffer ))! =-1 ){
Outstream. Write (buffer, 0, nbytes );
}
Outstream. Flush ();
Outstream. Close ();
Blobstream. Close ();
}
Catch (exception e ){
System. Out. println (E );
}
%>