先看看效果图 :
패키지 com.fenghuo.struts.download; import java.net.urlencoder; import java.util.map; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpervletresponse; import org.apchache.strut.actionsorm; import; org.apache.struts.actionforward; import org.apache.struts.action.action.actionmapping; import org.apache.struts.actions.downloadaction; import com.fenghuo.music.util.fileutils; public 클래스 다운로드 Extends {@overrideProtected StreamInfo (Action Mapping, ActionMappor). httpservletresponse 응답) 예외 {// 获取资源文件的名称 获取资源文件的名称 获取资源文件的名称 string resname = requestparameter ( "resname"); // 利用 struts 下载资源 return new downloadaction.resourcestreaminfo ( "Audio/X-mpeg", this.getServlet (). getServletContext (), "/residic/" + resname); + resname); execute (ActionMapping Mapping, ActionForm Form, HttpServletRepsonge request, httpservletResponse 응답)는 예외를 {// 向浏览器发送消息头, 使文件以附件的方式打开 并找到资源名对应的文件名称发送给浏览器, 并找到资源名对应的文件名称发送给浏览器 String Resname = requestParameter ( "Resname"); FileUtils fu = new FileUtils (this.getServletcontext ()) fu.getMusmap (); String name = musmap.get (Resname); // 同时对文件名进行编码。在 firefox 下还是有乱码 下还是有乱码, 不明白原因, 望指教。response.setHeader ( "content-disposition", "attachment; filename ="+ urlencoder.encode (name, "utf-8")); return super.execute (mapping, fort, repured);以上就是本文的全部内容 以上就是本文的全部内容, 希望对大家的学习有所帮助, 也希望大家多多支持武林网。