struts
-------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
 
 
<struts>
     <package name="struts2" extends="struts-default">
         <action name="uploadAction" class="com.lkw.action.UploadAction">
                  <result name="success">showfile.jsp</result>
          </action>
      <action name="downloadfile2" class="com.lkw.action.DownloadAction2">
           <result name="success" type="stream">
              <param name="contentDisposition">attachment;filename=${filename}</param>
              <param name="inputName">downloadFile</param>
           </result>
        </action>
        </package>
</struts>
-----------------------------------------------------------------------------------
action
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionSupport;public class UploadAction extends ActionSupport {
   private File file;
   private String fileFileName;//获取文件名,命名规则为:filename+FileName
   private String fileContentType;//获取文件的类型,命名规则为:filename+ContentType
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public String getFileFileName() {
return fileFileName;
}
public void setFileFileName(String fileFileName) {
this.fileFileName = fileFileName;
}
public String getFileContentType() {
return fileContentType;
}
public void setFileContentType(String fileContentType) {
this.fileContentType = fileContentType;
}
@Override
public String execute() throws Exception {
InputStream is = new FileInputStream(file);
String root=ServletActionContext.getServletContext().getRealPath("/upload");
System.out.println("root:"+root);
System.out.println("file:"+file.getName());
System.out.println("fileFileName:"+fileFileName);

File f = new File(root,fileFileName);
OutputStream os = new FileOutputStream(f);
byte buffer[]= new byte[1024];
int length=0;
while((length=is.read(buffer))>0){
 os.write(buffer, 0, length);
}
os.close();
is.close();
return "success";
}
   
}
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionSupport;public class DownloadAction2 extends ActionSupport {
      private String filename;
      private String name;    
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
      

public InputStream getDownloadFile(){
FileInputStream is=null;
try {
  String path=ServletActionContext.getServletContext().getRealPath("/upload");
                  this.name=new String(this.name.getBytes("ISO-8859-1"),"UTF-8");
  this.filename=name;
  path=path+File.separator+this.filename;
  System.out.println("filename="+this.filename);
  System.out.println("name="+this.name);
  System.out.println("path="+path);
  File f = new File(path);
  is = new FileInputStream(f);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


      System.out.println("is="+is);

return is;
}
@Override
public String execute() throws Exception {

return "success";
}
      
      
}--------------------------------------------------------------------------------------
fileUpload.jsp<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
  <head>
     <title>fileUpload</title>
    </head>
   <body>
       <form action="uploadAction.action" method="post" enctype="multipart/form-data">
         
           file:<input type="file" name="file"/><br/>
           
           <input type="submit" value="submit">
           
       </form>
  </body>
</html>
showfile.jsp<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
  <head>
     <title>fileUploadResult</title>
    </head>
  
  <body>
      
        name:<s:property value="fileFileName"/><br/>
        type:<s:property value="fileContentType"/><br>
      
        <a href="downloadfile2.action?name=${fileFileName}">文件下载</a>
  </body>
</html>----------------
不知道为什么会这样???struts2  中文文件下载乱码