The moose likes JSF and the fly likes Upload Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Upload" Watch "Upload" New topic


Dura Hurtado
Ranch Hand

Joined: Feb 16, 2011
Posts: 120
Hi , My would like upload a file to a server the example class which primefaces gives us is:

public class FileUploadController {

//private Logger logger = LoggerFactory.getLogger(FileUploadController.class);

public void handleFileUpload(FileUploadEvent event) {
//"Uploaded: {}", event.getFile().getFileName());

FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);

┬┐Could I specified a folder on the server?

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17421

No you cannot. A Web server is not a File Server. When you upload a file from a web browser, what you are really doing is telling the browser to open the selected file and copy its contents to the HTTP(S) request data stream as part of a Multipart MIME FORM POST operation.

When the server receives that data stream, it's up to the application to figure out what to do with the data, and that may or may not include ever writing the data to a server file at all. And if you do write the data to a file, it's your application that defines what the filename written will be, whether it's to simply use the name that was passed from the client as part of the incoming request or some other name of your own devising.

If you want to make your server accept file upload locations, they, too are whatever and wherever your application wishes, as long as the app has the appropriate file and directory access tights. However, you should NEVER upload files into your WAR or into any of the J2EE server's directories. If you do, you may experience great pain.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Upload
It's not a secret anymore!