Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java method call in Jscript function.  RSS feed

 
p tomar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
i have jsp page in my java application where i have The Close menu() function(javascript), that function
close the application onclick of close link . now i want to insert that close information into data base,

so i declare a method in jsp declaration tag (<%!>) , in method i fetch he information from request and create
DB conncetion and insert detail into Database.

i called that method as expression (<%= %> ) in closeMenu() JS function, but it called the java method onload of JSP page.. not in the closeMenu() function call.
i.e insert the Close Information into the DB at the time of Jsp page load inspite of Onclick of CloseMenu() function

can you suggest me where i m wrong, or any solution of that problem

i have to write that code in that same JSP page i don.t have other option to create new Servlets of other Html page

Any small suggestion will be helpful for me.

Thanks & Regard's
Paritosh
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Impossible. The code in the JSP runs on the server long before the page is sent to the client where an JavaScript (not JScript) can execute.

Please read this article to understand how JSP works and why what you ask can never be,
 
p tomar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi thanks for your reply..

So is there any other way to call the java mehods to make the entry in Database on Click of linkin JSP page.

i tried by making a new class where a defined new java method and include the class in My jsp page ..

so now can i call that java methods on click of Link button in JSp page..

Please suggest me..any solution ...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
p tomar wrote:i tried by making a new class where a defined new java method and include the class in My jsp page ..

Did you read the article? If so, read it again because you did not understand it. Once the JSP executes and sends the response to the browser, it is gone. So including anything in it is useless.

You'll need to make a new request to a servlet when the button is clicked, either by submitting the page or via Ajax.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!