• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing parameters to on load method of body tag from java

 
mona verma
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Passing parameters from java to javascript method called on load of body tag.
I have code as -
body on load = add(3);
but i dont want to hard code 3 but need this from java code.
so how can i send this value while redirecting to html from java.
[ December 15, 2008: Message edited by: mona verma ]
 
Sai Surya
Ranch Hand
Posts: 463
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mona,

So is your Javascript method is inside JSP? If so,
you can do like this...



In the body tag...
body onLoad javascript:add('<%=variableInJSPExpressionTag%>')


Make sure to put variable 'variableInJSPExpressionTag' into the request
in your servlet before dispatching to JSP.

And in JSP...
<%
int variableInJSPExpressionTag = Integer.valueOf(request.getParameter('variableInJSPExpressionTag')).intValue();
%>

Hope this helps.

[ December 16, 2008: Message edited by: Sai Surya ]

[ December 16, 2008: Message edited by: Sai Surya ]
[ December 16, 2008: Message edited by: Sai Surya ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Except, of course, you should no longer be using scriptlets and should be using the JSTL and EL.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!