This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to let javascript function recgonize java bean?

 
W Sun
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using javabean and javascript in a jsp page, and having problems passing parameters to javascript function:
-------------------------------------------------------
Problem 1:

------------------------------------
Problem 2:
This is a sample jsp page. I tried two ways(two buttons in the form) to pass a variable in the jsp page to the javascript function, none of them works.
When the first button is pushed, there's no response.
When the second button is pushed, the status bar shows "Script Error!".
Any idea? Thanks!


You need to remove the space in "on click" and "on load"
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't mix JSP and Javascript in this way.
JSP runs on the server to format an HTML page (containing your javascript) to send to the browser. Once the page is sent, the JSP and its beans go out of scope. By the time your page displays and your Javascript gets executed, your bean is long gone.
You can use JSP and beans to help create the Javascript that is sent to the page, but that's the extent of their interaction.
hth,
bear
[ September 19, 2003: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. If you perform a View Source on your page, you will see that what is sent to the browser is a pure HTML/Javascript page -- no Java, no beans, no JSP.
 
Sanjeev Kaushik
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem 1

Use in the same way you have written in Welcome line.
Problem 2
Use the code updated below
 
Sanjeev Kaushik
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats correct.
Java part is active at server side only.
HTML/Javascript is active in the browser(client side) only.
 
W Sun
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much! Now I have a better understanding about jsp and javascript(novice in both areas). Also I tried the alert statements and it works perfect (it works in server environment not otherwise). Actually the two problem seems addressed the same point. I guess I can always use the measure in the 2nd one to handle the situation in the 1st one: pass a variable got from the bean. Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic