How can I get the uploaded file (for example a text file) to display in a string after it is selected?
FileUpload fileUpload = new FileUpload();
panel.add(fileUploa开发者_运维知识库d);
panel.add(btnSubmit);
You can't get the contents of a file selected by the user without uploading it to your server first.
As explained in the FileUpload
documentation a FileUpload
needs to be wrapped in a FormPanel
that uses multipart encoding. Once the form is submitted your application can request the file contents from the server (or they could be included in the response to the request that uploaded the file) and then displayed by your application.
In addition to what Jason said, if you want only the user selected file name, before sending to the server, you can use FileUpload#getFilename()
精彩评论