当前位置: 代码迷 >> Java Web开发 >> 怎么用JSP实现JSP下载文件功能
  详细解决方案

怎么用JSP实现JSP下载文件功能

热度:69   发布时间:2016-04-17 12:44:00.0
如何用JSP实现JSP下载文件功能?
如何实现下述功能:
1)点击按钮,并取得服务器上的文件
2)出现保存文件对话框,用户可以保存该文件或者取消,并且对话框能知道文件类型。

------解决方案--------------------
有个第三方Bean让你用:jspsmart;
------解决方案--------------------
嗯,可以用第三方jar包,就是楼上说的SmartUpLoad就可以了!
------解决方案--------------------
直接用java的读写流类就可以了,读取文件写到response里面,frush一下就直接弹出文件保存的对话框了,这是浏览器自带的。有一个参数就是设置文件名的,不仅仅是扩展名,全名都有

------解决方案--------------------
类似这样

Java code
public ActionForward download(ActionMapping mapping, ActionForm form,            HttpServletRequest request, HttpServletResponse response)            throws Exception {        if (logger.isDebugEnabled()) {            logger.debug("entering 'AttachmentAction.download()' method...");        }        ActionMessages messages = new ActionMessages();        String id = request.getParameter("id");        String attachmentFile=request.getParameter("file");        String type = request.getParameter("type");        if (id != null||attachmentFile!=null) {            Attachment attachment =null;            if(id!=null) {                attachment= mgr.view(id);            } elseta.x
------解决方案--------------------
SmartUpLoad就可以了

或者cos
  相关解决方案