• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

not able to call javascript function

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
reply
    Bookmark Topic Watch Topic
  • New Topic