aspose file tools*
The moose likes JSP and the fly likes how to let javascript function recgonize java bean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "how to let javascript function recgonize java bean?" Watch "how to let javascript function recgonize java bean?" New topic
Author

how to let javascript function recgonize java bean?

W Sun
Greenhorn

Joined: Apr 24, 2003
Posts: 6
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

Joined: Jan 10, 2002
Posts: 61760
    
  67

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61760
    
  67

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

Joined: Aug 01, 2002
Posts: 105
Problem 1

Use in the same way you have written in Welcome line.
Problem 2
Use the code updated below


Sanjeev Kaushik
Sanjeev Kaushik
Ranch Hand

Joined: Aug 01, 2002
Posts: 105
Thats correct.
Java part is active at server side only.
HTML/Javascript is active in the browser(client side) only.
W Sun
Greenhorn

Joined: Apr 24, 2003
Posts: 6
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to let javascript function recgonize java bean?