struts下载

struts.xml

 <action name="upDown_*" class="com.struts.updown.UpDownAction" method="{1}">
   <result>ok.jsp</result>
   <result name="input">error.jsp</result>
   <result name="downfile" type="stream">
    <param name="contentType">application/xml</param>   
    <param name="inputName">downfileinput</param>
    <param name="contentDisposition">attachment;filename=${downfileFileName}</param>
    <param name="bufferSize">4096</param>
   </result>
  </action>

inputName:下载文件的流

 

java:

 private String downfileFileName;
 private String downfilePath;
 private InputStream downfileinput;
 
 public String DownCn(){
  downfileFileName="副本.xml";
  String path = ServletActionContext.getServletContext().getRealPath("/")+"upload";
  try {
   downfileinput=new FileInputStream(path+"/"+downfileFileName);
   downfileFileName=new String(downfileFileName.getBytes(), "ISO8859-1");//控制中文名称
  } catch (FileNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }catch (UnsupportedEncodingException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return "downfile";
 }

 

你可能感兴趣的:(java,下载文件,private)