0

Hi,

I want to get only the filename from the entire path in a file dialog in JSP. Right now I am using type "file" in input tag.

any help will be appreciated.

cheers!

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by __avd
0

There is not jsp dialog user interface for file selection. It's a input type file html tag.
If you want to get filename only in your server side (java) code then use,

File s=new File("c:\\aa\\b.txt");
System.out.println(s.getName());

Use following javascript code to get filename.

....
<script type="text/javascript">
   function doit() {
    var v=form1.file.value; 
    alert(v.substring(v.lastIndexOf("\\")+1));
   }
</script>
 ....
<form method="post" name="form1">
<input type="file" name="file"/>
  <input type="button" value="Test" onclick="doit()"/>
</form>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.