|
Rewrite process in ActionServlet, add a line
request.setCharacterEncoding ("GB2312");
The download method in the action class is as follows:
private boolean download (String id, HttpServletRequest request, HttpServletResponse response) {
// Set the response header and file name for download
Ranch
response.reset ();
response.setContentType ("APPLICATION / OCTET-STREAM; charset = GB2312");
// try {
response.setHeader ("Content-Disposition",
"attachment; filename =\" "+ id +" .jar\"");
//} catch (UnsupportedEncodingException e) {
// System.out.println (e);
//}
if (debug) {
System.out.println ("download at");
}
boolean b = false;
DbConnection db = null;
Connection conn = null;
Statement st = null;
String sql = "select CONTENT from DIC_PLUGINS where id = '" + id + "'";
if (debug) {
System.out.println (sql);
}
ResultSet rs = null;
Blob blob = null;
try {
db = new DbConnection ();
db.openConnection ();
conn = db.getConnection ();
st = conn.createStatement ();
rs = st.executeQuery (sql);
if (rs.next ()) {
blob = rs.getBlob ("CONTENT");
}
} catch (Exception e) {
System.out.println (e);
} finally {
try {
if (rs! = null)
rs.close ();
if (st! = null)
st.close ();
if (conn! = null)
conn.close ();
if (db! = null)
db.close ();
} catch (Exception e) {
System.out.println (e);
}
}
if (debug) {
System.out.println ("write");
}
// write stream information
if (blob! = null) {
InputStream fileInputStream = null;
int size = 0;
try {
fileInputStream = blob.getBinaryStream ();
size = (int) blob.length ();
} catch (SQLException e) {
System.out.println (e);
}
byte [] bytes = new byte [size];
// fileInputStream.read (bytes);
int i = 0;
Ranch
if (debug) {
System.out.println ("last");
}
try {
while ((i = fileInputStream.read (bytes))! = -1) {
response.getOutputStream (). write (bytes, 0, i);
}
Ranch
fileInputStream.close ();
response.getOutputStream (). flush ();
b = true;
} catch (Exception e) {
System.out.println (e);
}
}
return b;
} |
|