File Upload in Jfinal and Jfinal File Upload

Source: Internet
Author: User

File Upload in Jfinal and Jfinal File Upload

File Upload and import the corresponding package. You only need one code (the imported package is Baidu)

1 public UploadFile getFile(String parameterName, String saveDirectory, Integer maxPostSize, String encoding)2 3 public List<UploadFile> getFiles(String saveDirectory, Integer maxPostSize, String encoding)

Two Methods: pass in a single file on the first jsp page, and pass in multiple files on the second.

ParameterName corresponds to <input name = "corresponding to this name"/>

For example:

1 public class FileController extends Controller {2 public void upload () {3 try {4 // if the second parameter is a, save it to the upload/a folder, automatically create a folder 5 UploadFile file = getFile ("photo", "a", 100*1024*1024, "UTF-8"); 6 7 8} catch (Exception exception) {9 System. out. println ("path error"); 10} 11 renderJsp ("/pages/success. jsp "); 12} 13}

The file will be stored in the upload under the project added in your tomcat

Custom path:
1 public class JConfig extends JFinalConfig {2 3 @ Override4 public void configConstant (Constants me) {5 // development mode 6 me. setDevMode (true); 7 me. setViewType (ViewType. JSP); 8 me. setBaseUploadPath ("D: // upload"); 9}

Use me. setBaseUploadPath ("D: // upload"). For example, set the path to D: // upload in the code.

When you upload a file later, the path parameter you fill in will be added to this end. You do not need to fill in the file name and will automatically save it as the uploaded file name.

You can modify the file name to be uploaded at the front end (not tried)

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.