I want to call a function of javascript from servlet.
servlet code:
File ff = new File(uploadedFile+"/"+fileName+".mp4");
FileOutputStream fileOutSt = new FileOutputStream( ff );
fileOutSt.write(data);
fileOutSt.close();
request.setAttribute("src", ff);
RequestDispatcher dispatcher=request.getRequestDispatcher("/WEB-INF/jsfunction.js");
dispatcher.include(request, response);
my javascript code:
myfunction(fileInput)
{
var fileUrl = window.URL.createObjectURL(fileInput);
}
The problem is javascript calls but it display the code content but not execute it. how can i get fileURL.
Several things are wrong here:
First, the inclusion of your javascript source is improper, because the javascript must be included (or referenced) always within an HTML file. In your case, instead, you are serving a MP4 file.
If you must absolutely execute that js code (remember that js is always executed in a browser), I suggest you serve an HTML page instead. In this case, the jsfunction.js script must be referenced within the HTML code:
<html>
<head>
<script type="text/javascript" src="jsfunction.js" />
</head>
<body>
...
</body>
</html>
Second: Even if you include the script, you must then invoke your function. You can call it immediately, from a scriptlet, or as a response to some client event (onclick, onload, etc).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With