Get full path of selected file in JSF

前端 未结 1 1468
时光取名叫无心
时光取名叫无心 2021-01-17 03:46

I need a JSF button which allows user to browse and select a particular file, then I need my program to retrieve full path of the file.

This functionality is requir

相关标签:
1条回答
  • 2021-01-17 04:03

    The JSF <h:inputFile> component generates a HTML <input type="file"> element which is officially only capable of sending the file content along with the sole file name — although certain browsers, particularly the one developed by some team in Redmond, also send the full file path along with the file name due to a security bug; which should thus certainly not be relied upon as it may be fixed and removed in future versions.

    In HTML terms, there does not exist any element which allows the enduser to select a full file path from its local disk file system and send it in its entirety (without the associated file content) to the server. Since JSF is in the context of this question merely a HTML code producer, it isn't possible in JSF either.

    Consider creating a Swing based Applet which you in turn embed the usual way in your HTML page (or JSF page, depending on the perspective how you interpret things). The Swing JFileChooser is capable of the task of selecting a local disk file system location and obtaining the full path. You can in turn send this information via URLConnection to the server (don't forget to sign the applet to avoid bothering and worrying the enduser about the security warnings it may produce).

    0 讨论(0)
提交回复
热议问题