日期:2014-05-18  浏览次数:20767 次

如何用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