Download multiple files in JSP

xiaoxiao2021-03-06  84

Theme: JSP in how to achieve download multiple files Author: babymon () reputation value: 100 Quantity Forum: Java JSP / Servlet / JavaBean questions Points: 50 Replies: 6 Published: 2004-8-25 17: 01: 50JSP How to achieve a directory that downloads multiple files to a user, which means that the directory can only be selected when the user is downloaded.

You cannot change the file name. Thanks to everybody !!!!

Reply to: Yys79 (Shart-Shoot) () Reputation: 100 2004-8-25 17:41:30 Score: 0 It seems that it is impossible, any download software is also a download. At the same time, download the client software, the B / S structure is not

TOP

Reply to: babymon () () Reputation: 100 2004-8-25 19:04:46 Score: 0 Then I can implement multiple files of the application server to the client, and the destination directory is the user selectable.

My application server is WebLogic8

TOP

Reply to: Power17 () () Reputation: 105 2004-8-26 1:12:01 Score: 10 I wrote, using jspsmartupload.

However, there are two questions:

1. I use java.io.file file = new java.io.file ("."); The resulting directory is C: / Windows / System32 /.

I have to run a lot of friends on the Internet, the result is a certain level directory under Tomcat. Later changed to the following

G: // Web // Tomcat 5.0 // WebApps // Root // Upload (a certain level directory in my Tomcat installation directory),

It is unsuccessful to the catalog adjustment

2. You cannot download files in .txt format (open in your browser).

3. All the files after downloading have become a thumbs.db file, I don't know what this is useful.

The following is my code, strongly welcome to correct.

<% @ Page ContentType = "Text / HTML; Charset = GB2312" Language = "Java" IMPORT = "com.jspsmart.upload. *"%>

<% @ Page Import = "java.io. *"%>

No title document </ Title></p> <p></ hEAD></p> <p><body></p> <p><%</p> <p>Java.io.file file = new java.io.file ("g: // Web // Tomcat 5.0 // WebApps // Root // UPLOAD");</p> <p>// Get all files in the specified directory</p> <p>Java.io.file [] files = file.listfiles ();</p> <p>// Number of details</p> <p>INT count = files.length;</p> <p>// Download with JSPSMARTUPLAOD components</p> <p>Smartupload su = new smartupload (); Su.initialize (PageContext);</p> <p>Su.setContentDisPosition (NULL);</p> <p>For (int i = 0; i <count; i ) {</p> <p>String flnm = files [i] .GetabsolutePath ();</p> <p>Su.Downloadfile (FLNM);</p> <p>}</p> <p>%></p> <p></ body></p> <p></ html></p> <p>TOP</p> <p>Reply to: GJD111686 (Digital King) () Reputation: 100 2004-8-26 8:09:46 Score: 40 call this JS function</p> <p>Function Downurl (StrRemoteurl, Strlocalurl)</p> <p>{</p> <p>Try</p> <p>{</p> <p>VAR XMLHTTP = New ActiveXObject ("Microsoft.xmlhttp");</p> <p>XMLHTTP.Open ("Get", StrremoteURL, FALSE);</p> <p>Xmlhttp.send ();</p> <p>VAR AdodbStream = New ActiveXObject ("AdoDb.Stream");</p> <p>AdoDBStream.Type = 1; // 1 = adtypebinary</p> <p>AdoDBStream.open ();</p> <p>AdoDBStream.write (XMLHTTP.RESPONSEBODY);</p> <p>AdodbStream.savetofile (StrlocalURL, 2);</p> <p>Adodbstream.close ();</p> <p>Adodbstream = NULL;</p> <p>XMLHTTP = NULL;</p> <p>}</p> <p>Catch (e)</p> <p>{</p> <p>WINDOW.CONFIRM ("Download URL Error!");</p> <p>}</p> <p>//Window.confirm ("Download is complete.");</p> <p>}</p> <p>TOP</p> <p>Reply to: babymon () () Reputation: 100 2004-8-26 9:47:05 Score: 0 Good, try! !</p> <p>TOP</p> <p>Reply to: GJD111686 (Digital King) () Reputation: 100 2004-8-26 9:51:30 Score: 0 Use Applets You can:</p> <p>Public void readURL (String Strurl)</p> <p>{</p> <p>Try</p> <p>{</p> <p>Int IhtpResult;</p> <p>URL M_URL = New URL (StrURL);</p> <p>UrlConnection M_URLCONN = M_URL.OpenConnection ();</p> <p>m_urlconn.connect ();</p> <p>HTTPURLCONNECTION M_HTTPCONN = (httpurlconnection) m_urlconn;</p> <p>IHTTPRESULT = m_httpconn.getResponsecode ();</p> <p>IHTPRESULT! = httpurlconnection.http_ok)</p> <p>JOPTIONPANE.SHOWMESSAGEDIALOG (this, "Unable to connect ...");</p> <p>Else</p> <p>{</p> <p>INT ifilesize = m_urlconn.getContentLength ();</p> <p>InputStreamReader M_Reader = New InputStreamReader (M_URLCONN.GETITINPUTSTREAM ());</p> <p>Char [] buffer = new char [2048];</p> <p>INT INUM = 0;</p> <p>While (inum> -1)</p> <p>{</p> <p>InUM = m_reader.read (buffer);</p> <p>IF (Inum <0) Break;</p> <p>//JOPTIONPANE.SHOWMESSAGEDIALOG (THIS ,NEW STRING (Buffer, 0, Inum);}</p> <p>M_Reader.close ();</p> <p>}</p> <p>}</p> <p>Catch (Exception E)</p> <p>{</p> <p>JOPTIONPANE.SHOWMESSAGEDIALOG (this, E.GETMESSAGE ());</p> <p>}</p> <p>}</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-106721.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="106721" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.038</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'BTr749PEwZu6pRrRiy1lx7ESfjHJ9U472c1_2F0mboYPWNUoxtpMC1CxMONecuBtoMHUZm_2FkVQO7p_2BygpNg4FVDA_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>