I want to call JavaScript function from a servlet using jQuery.
This is my JavaScript:
function showerrodailog(){
ShowDialogBox('Alert','No record found.','Ok','', 'GoToAssetList',null);
}
function ShowDialogBox(title, content, btn1text, btn2text, functionText, parameterList) {
var btn1css;
var btn2css;
if (btn1text == '') {
btn1css = "hidecss";
} else {
btn1css = "showcss";
}
if (btn2text == '') {
btn2css = "hidecss";
} else {
btn2css = "showcss";
}
$("#lblMessage").html(content);
$("#dialog").dialog({
resizable: false,
title: title,
modal: true,
width: '400px',
height: 'auto',
bgiframe: false,
hide: { effect: 'scale', duration: 400 },
buttons: [
{
text: btn1text,
"class": btn1css,
click: function () {
$("#dialog").dialog('close');
}
},
{
text: btn2text,
"class": btn2css,
click: function () {
$("#dialog").dialog('close');
}
}
]
});
}
I want to call this function from a servlet. How can I do that I tried from Google and find this code, however, I called that it says error $ not defined.
I used this for popup alert message.
/* ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine javascriptEngine = manager.getEngineByExtension("js");
// Get script from JS File
FileInputStream fileInputStream = new FileInputStream("F:\\workspace\\Userlogin\\WebContent\\js\\val.js");
if (fileInputStream != null) {
BufferedReader reader = new BufferedReader(new InputStreamReader(fileInputStream));
javascriptEngine.eval(reader);
Invocable invocableEngine = (Invocable)javascriptEngine;
// Invoke javascript function named "sayHello" with parameter "Atul"
Object object = invocableEngine.invokeFunction("sayHello", "Atul");
System.out.println("Result: " + object);*/
// }