In JSP page, inside a javascript function, can I place a java code using scriptlet tag?

In JSP page, inside a javascript function, can I place a java code using scriptlet tag?

Objective: When the user is trying to close a window, I need to check whether a particular list is empty or not. If its not empty, I need to make a hibernate call to do some action.

Did Coding as below: While the user is trying to close a window, I am calling a java script function closeWind() in jsp page.

In a separate java file, in a method checkListValue(), I am doing the logic of checking the list is empty or not, and making a hibernate call if its not empty.

Inside the javascript function closeWind(), I make a call to checkListValue() method using scriptlet tag.

My doubt here is, can I call the method checkListValue() using scriptlet tag inside the javascript function closeWind().

I tried this ,checkListValue() method is not getting called, but the alerts kept inside the java script function gets executed.

Pl help how to fix this issue.

Note: I did import the java file containing checkListValue() method in the jsp page

View Answers

October 3, 2013 at 11:56 AM


You can't run Java code on Client side. That's why you can't use Java code in closeWind() Javascript function.

What you can do is:

a) Write Ajax code in the closeWind() function for calling a Servlet/JSP on the server side.

b) You can get the data into a variable through ajax call

c) based on the value returned you can execute the relevant JavaScript.

Check: Simple Ajax Example, Developing Simple Ajax application


October 8, 2013 at 12:07 AM

Thanks for your reply..

October 8, 2013 at 12:07 AM

Thanks for your reply..

Related Tutorials/Questions & Answers:
In JSP page, inside a javascript function, can I place a java code using scriptlet tag?
i want to pass Javascript value to JSP scriptlet..
multiplication function in jsp using scriptlet function
Can i use Scriptlets inside javascript,if so how?
How I get a variable from java script to use it in the scriptlet of jsp.
user defined function inside a jsp
scriptlet tags in jsp - JSP-Interview Questions
can i Execute PHP code inside python script?
how to call the array variable in scriptlet from javascript function
Can i write JavaScript code in AjaxResponse Code ?
JSP Scriptlet
how to access element added via javascript dynamically using jsp code
Transferring values between javascript and java code in jsp - JSP-Servlet
JSP Scriptlet Tag
jsp scriptlet
Help with javascript function - JSP-Servlet
Java Function for block inside a block
Java Function for block inside a block
javascript abort function
how to display jsp page containing mysql query in particular division using ajax ?my code is below bt i cundt get it properly
Email validation is JSP using JavaScript
How To Page Refresh Using JavaScript In JSP
JSPs : Scriptlet
Uploading Single File by Using JSP
JSP Simple Examples
callig jsp file from javascript function - JSP-Servlet
How i can send mail by using jsp.............. - JavaMail
can i remopve a jsp web page - JSP-Interview Questions
How can i implement the calculator programe in jsp code
jsp page tags - JSP-Servlet
jsp function - JSP-Servlet
How ot get a web page title and meta tags in java(jsp/ servlet) - JSP-Servlet
code for user registration page and login page of emails using jsp
actually i want to knw how to include an google page inside a tab(suppose in 2nd tab).can any one help me....
How i write a function/method in jsp?
tree using jsp code
how to invoket javascript function in JSP - JSP-Interview Questions
Defining and using custom tags - JSP-Servlet
javascript code problem - JSP-Servlet
Where can I learn JavaScript
can any one give the frogort password code using jsp,
javascript Code - JSP-Servlet
How can I access databse through JSP. I am using postgresql-8.4.4-1-windows as database and jboss-4.0.5.GA as server.
Can I remove jsp web page from the server - JSP-Interview Questions
JSP Tags
how can i simplify my java code
How to export web page to excel using java or jsp or servlets
combox validation javascript code - JSP-Servlet
JSP Value to JavaScript
Register page using servlets,jsp and java beans