Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

not able to call javascript function  RSS feed

 
Varun Dikshit
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Here's the description of a problem I'm facing:

I call a servlet from a JSP which after some processing calls back the JSP using requestDispatcher. On this return call to JSP, a javascript function is not reachable. What might be the problem?

The code hierarchy in my JSP is scriptlets, html head(link to .css and script lang definition including src="treeJS.js"), html body(expression-calling a java mthd in scriptlet), form

Rgds
Varun
 
sudhir kamath
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
java script is event based. so on load of forms body you have to call java acript method.
regards,
sundeep
 
Varun Dikshit
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sundeep, thanks for replying!
Let me explain the situation better. On load of the jsp page, a scriptlet is called which in turn calls thejavascript function. So, I cannot call the javascript function.
There is no problem when the page is first loaded but when the call goes to the servlet which, in turn, calls the previous JSP, I get an error which says that a particular javascript function is undefined.

Hope I have been able to make my doubt clear Any help would be acknowledged!
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A scriptlet can not be called from a javascript onload event.
Scriptlets as well as custom tags, EL, JSTL, etc.. are all executed on the server. Javascript is inerpreted in the browser on the client.

Why don't you post your code with an explanation of what you're trying to do.
 
Varun Dikshit
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The skeleton is like this:

1)clientFile.jsp


2)MyServlet.java



3)ObjXXX.java



4)javScript.js



The calls are:
JSP->Servlet->JSP (both JSPs are the same)
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want your javascript functions invoked when the page loads, add the call to the onload event in the body tag:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!