原代码:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
String strFileName = request.getParameter("fujian");
System.out.println(strFileName);
String filepath=request.getRealPath("/");
File file = new File(filepath+"/fujian/" + strFileName);//
if(file.exists()){
try{
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
byte[] buffer = new byte[1024];
strFileName = java.net.URLEncoder.encode(strFileName, "UTF-8");//处理中文文件名的问题
strFileName = new String(strFileName.getBytes("UTF-8"),"GBK");//处理中文文件名的问题
response.reset();
response.setCharacterEncoding("UTF-8");
response.setContentType("application/x-rar-compressed");//不同类型的文件对应不同的MIME类型
response.setHeader("Content-Disposition","attachment; filename="+strFileName);
OutputStream os = response.getOutputStream();
while(bis.read(buffer) > 0){
os.write(buffer);
}
bis.close();
os.close();
return mapping.findForward("suc"); }
catch(Exception e){
return mapping.findForward("fail");
}
}else{
return mapping.findForward("fail"); }
请问什么原因?
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
String strFileName = request.getParameter("fujian");
System.out.println(strFileName);
String filepath=request.getRealPath("/");
File file = new File(filepath+"/fujian/" + strFileName);//
if(file.exists()){
try{
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
byte[] buffer = new byte[1024];
strFileName = java.net.URLEncoder.encode(strFileName, "UTF-8");//处理中文文件名的问题
strFileName = new String(strFileName.getBytes("UTF-8"),"GBK");//处理中文文件名的问题
response.reset();
response.setCharacterEncoding("UTF-8");
response.setContentType("application/x-rar-compressed");//不同类型的文件对应不同的MIME类型
response.setHeader("Content-Disposition","attachment; filename="+strFileName);
OutputStream os = response.getOutputStream();
while(bis.read(buffer) > 0){
os.write(buffer);
}
bis.close();
os.close();
return mapping.findForward("suc"); }
catch(Exception e){
return mapping.findForward("fail");
}
}else{
return mapping.findForward("fail"); }
请问什么原因?
看看你的struts_config.xml的配置有没有fail的