<script>
function a(){
var filename="test.txt";
</script>

<img src="img/test.png" title="?"/>

How to get the value of "filename" in "title"?

you are asking in the wrong forum.
for jsp, there is a separate jsp forum.

also: you are trying to mix javascript (not java) with html, which is not really java/jsp related, maybe you should consider posting it in the Javascript forum

What event do you want to happen to initiate the process of getting the value in the function into the title attribute?

<body onload="a()"> 

<script>
function a(){
   var filename="test.txt";
   document.getElementById("img1").title=filename;
} 
</script>

<img id="img1" src="img/test.png" title="?"/>

</body>

on mouseHover event I want to display the title of image tag, which is by default event.

my question is how to get value of fileName in title attribute?

Hi,
Do you want to display the file name from src in title of img tag?
You can use this, dont need javascript for that:
<img src="img/test.png" title="test.png"/>

I want value of variable, "filename" not the static file name.

In this case JorgeM give you the right solution.