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!

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>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.