java - How to pass bean value to javascript in jsp? -
java - How to pass bean value to javascript in jsp? -
i trying pass int bean jsp page (using <%= testbean.getnumber()%>).
but when trying pass javascript in page, it's giving me error says: "non-static method cannot referenced in static context". trying form loop in script, like:
(int = 0; < (<%= testbean.getnumber()%>); i++) { // } anyone knows how pass bean value javascript? thanks.
your bean name testbean looks class name.
the compiler thinks trying access class method (an static method). if trying phone call instance method (non static), need define name of bean instance.
the convention classes start uppercase names , instances utilize lowercase name. seek declaring bean instance next rule (lowercase name).
for instance:
<html> <head> <script> <% class samplebean { string _value; public string getvalue () { homecoming _value; } public void setvalue (string value) { _value = value; } } samplebean sb = new samplebean(); sb.setvalue("hello world!"); %> v = "<%= sb.getvalue() %>"; </script> </head> <body> <a href="javascript:alert(v)">click me!</a> </body> </html> java javascript jsp javabeans
Comments
Post a Comment