I am developing a web application in which for User Registration the user has to select a profile picture and then click on upload button.
So, my question is how to get FileName
which user has selected and display.
I am using Struts 2 and JSP.
I am developing a web application in which for User Registration the user has to select a profile picture and then click on upload button.
So, my question is how to get FileName
which user has selected and display.
I am using Struts 2 and JSP.
if The input tag you are using in your html is
<input type="file" name="MyFile" id="MyFile" />
then you can retrieve your file name in javascript by using the following code
var fileName = document.getElementById('MyFile').value;
But for some security reasons, browsers won't allow you retrieve full filepath of your file.
But I heard old versions of Internet Explorer gives you file path.
Good Luck!
If you use the property uploadFileName
along with upload
property to the action that accepts uploading a file, i.e. the fileUpload
interceptor is applied to the action configuration then it will be populated. There's also uploadContentType
attribute that could be populated.
private File upload;
private String uploadContentType;
private String uploadFileName;
//getters ans setters assumed
in the JSP use the name
attribute to map it to the action
<s:file name="upload"/>