Reputation: 29
i have a JavaScript function
function ShowDeptPanel()
{
document.getElementById("table1").style.visibility="hidden";
document.getElementById("table2").style.visibility="visible";
}
which is defined in JSP page, but i want to call it from Servlet. How can i do this ?
Note: i want to disable 1 table after a certain check in my Servlet Code.
Upvotes: 1
Views: 1669
Reputation: 18576
In your JSP, use scriptlet to call the servlet function and get the result.
If we consider it to be boolean value, then
<script type="text/javascript">
function ShowDeptPanel()
{
document.getElementById("table1").style.visibility="hidden";
document.getElementById("table2").style.visibility="visible";
}
var serverCheck = <% JavaClass classObject = JavaClass.getInstance();
classObject.getMethodChecking();%>;
if(serverCheck==="true") {
ShowDeptPanel();
}
</script>
This is one way to hide the table. If you want it to be dynamic, make ajax call to the servlet and make the servlet return you the response which can be processed in javascript to hide / show the table.
Upvotes: -1
Reputation: 1327
Javascript is client-side, so it HAS TO be executed from the web browser. If what you want to do is execute javascript at the page loading, after a specific servlet has been executed, you can do the following :
executeScript
) in the request attributestrue
If you servlet always sends the same page, then just add you javascript function call in the onload
attribute of your HTML <body>
tag
Upvotes: 2