Java WEB file download
Now we want to use the springMVC-based file download function.
Is not effective
Where is the problem?
After clicking the link, if it is a text file, it will be automatically opened instead of downloaded. If it is an image, it will be opened rather than downloaded.
So what should we do? After research, File
File Upload and File Download are two common functions in Web applications. In Java, there are also many ways to implement these two functions, here, struts2 provides us with a relatively simple method. Let's take a look at it. First, let's look at file upload:
File Upload
When uploading files, we should first note the form on the upload page. This form is also exquisite, because the data in the submitted
(); I can write anything in bytes.//Writes the contents of int i; while ((i = Buff.read ())! =-1) {out.write (i); }//Push the contents into the document Out.flush (); }else{return "Download fail";//File Not Present}} catch (Exception e) {//To Do:handle exception}finally{try {if (buff! = null) b Uff.close (); if (out! = null) out.close (); } catch (IOException
Download and preliminary use of the Eclipse IDE for Java EE developers
Recently, I want to write a small project with eclipse, suddenly found that the previous eclipse does not support TOMCAT8, the Internet to find a way, more trouble, had to own the next version, by the way review Eclipse software use.
1.Eclipse DownloadUse of 2.Eclipse3.Eclipse a few use tips 1.Eclipse
continues to pass byte[] buffer =New byte[32]; intLen =-1; //At the beginning of each copy, the pointer to the source file and the pointer to the target file must be read from the last disconnected position . while(len = rafsrc.read (buffer))! =-1) {rafdes.write (buffer,0, Len); //when the profile is written, each time the file pointer is moved to its original location-so that it will only store the first 8 bytesRafconfig.seek (0); //each copy of the sum, hurriedly record
(httpservletresponse response) {
//Get Site Deployment path (via ServletContext object) to determine the location of the download file for download
String path = Servletcontext.getrealpath ("/");
//1. Set the file contenttype type so that it will automatically determine the type of download file
Response.setcontenttype ("Multipart/form-data");
//
1, the Java? Tutorials Download site :Http://www.oracle.com/technetwork/java/javase/java-tutorial-downloads-2005894.html2, the Java? Tutorials Online address :http://docs.oracle.com/javase/tutorial/1, Java Platform standard Editi
Java PDF file implementation method [attached PDFRenderer. jar download], export PDFRenderer. jar
This example describes how to implement PDF files in java. We will share this with you for your reference. The details are as follows:
In a recent website, you need to upload a pdf file, display a pdf page, and click the page to read it online. Here PDFRender is used
Write in front"File Upload and download" is a lot of system features, such as PM\OA\ERP, etc., the common development mode of the system has B/s and C/s, while the former is mainly through the browser to access the Web server, generally using the seven layer Protocol "application layer HTTP" for data transmission, The latter mainly through the programming language development of the app as a client to access the server, generally using the seven layer
, Plainsocketfactory.getsocketfactory ())); Schreg.register ("https", 443, Sslsocketfactory.getsocketfactory ()));//multi-connected thread-Safe manager poolingclientconnectionmanager PCCM = new Poolingclientconnectionmanager (Schreg);p Ccm.setdefaultmaxperroute (50); Maximum number of parallel links per host pccm.setmaxtotal (100); Client total parallel link Maximum number HttpclieNT = new Defaulthttpclient (PCCM, params); Httpclient.getconnectionmanager (). Closeidleconnections (10, Timeunit.se
; } }, "JSON" ); } } ); }This is the download of the attachment JS, where Appattachmentid is the attachment pathfunction Exportsingle (appattachmentid) { var url = bootpath+ "/inner/uploadfile_downloadfile.action? Appattachmentid= "+appattachmentid; $ ("#actionForm"). attr ("action", URL). Submit (); Then the Java code:To upload an attachment t
deployment path (via the ServletContext object), which is used to determine the download file location for downloadString Path = Servletcontext.getrealpath ("/"); //1. Set the file contenttype type, this setting, will automatically determine the download file typeResponse.setcontenttype ("Multipart/form-data"); //2. Set the file header: The last parameter is to set the
Java 8 upadate Kit downloadHttp://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.htmlJava Development Documentation Http://docs.oracle.com/javase/8/docsenvironment variable settings after installation is completeComputer | Properties | Advanced system settings, pop-up System Properties dialog box, go to Advanced tab, select environment variable settingsIn the system variable in the
TortoiseSVN (Turtle svn) is a free open source client of Subversion version control system that can manage files and directories beyond the time. Files are saved in the central repository, and the repository is very much like a normal file server, except that you can remember every modification of the file and directory. You can restore files to a previous version, and you can check the history to see what changes were made to the data and who made the changes. That's why many people regard Subv
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.