
Hi All,
I've a requirement as,
1) Need to browse a file from my local system/machine
2) Path of the file from which I browsed need to be stored in a variable in controllerbean.
This thing I've done as below,
1)...
filePathAccess.jsp
< ice:inputFile id="inputFileName" width="600" autoUpload="true" value="#{fileAccessDataBean.inputFileName}" actionListener="#{fileAccessControllerBean.browse}" />
2)...
FileAccessDataBean.java
private String inputFileName;
public String getInputFileName() {
return inputFileName;
}
public void setInputFileName(String inputFileName) {
this.inputFileName = inputFileName;
}
FileAccessControllerBean.java
public class FileAccessControllerBean {
/** latest file uploaded by client. */
private FileInfo currentFile;
FileAccessDataBean fileAccessDataBean = new FileAccessDataBean();
/** * This method is for gettingsetting browse. * @param event ActionEvent */
public void browse(ActionEvent event) {
InputFile inputFile = (InputFile) event.getSource();
String filePath = null;
LOG.debug("XXX Getting File Info into currentFile..." + inputFile);
currentFile = inputFile.getFileInfo();
LOG.info("XXX current File Name... " + currentFile.getFileName());
filePath = inputFile.getFileInfo().getPhysicalPath();
LOG.info("XXX physical path... " + filePath);
fileAccessDataBean.setInputFileName(inputFile.getFileInfo().getPhysicalPath());
File file = currentFile.getFile();
filePath = file.getAbsolutePath();
LOG.info("XXX absolute path.. " + filePath);
}
}
=========================================================
Browsed file location: C:\Documents and Settings\personInfo.xml
XXX Getting File Info into currentFile... personInfo.xml
XXX current File Name... personInfo.xml
XXX physical path File Name... U:\glassfish.frontend\domains....\personInfo.xml
XXX absolute path.. U:\glassfish.frontend\domains....\personInfo.xml
in the above two logs I'm getting serverpath of the file.. But I want exact browsed path that is C:\Documents and Settings\personInfo.xml
how can I get the path? Is there any other way to browse the file and get the path of the file into controllerbean?
PLEASE HELP ME OUT It's very urgent requirement for me.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.