Saturday, August 27, 2011

How to get javaScript variable to Java

In javascript function...

function mywork()
{
var q= "java";
document.SubmitForm.myelement.value=q;
document.SubmitForm.submit();
}

Under Jsp body.....


form name="SubmitForm" action="ActionSubmitForm" method="post"
input type="hidden" name="myelement"
input type="button" value="SUBMIT" onclick="mywork()"


In java...we can get the value of javascript variable "q" by

String str=request.getParameter("myelement");
System.out.println(str);

// here we can get the value of str as "java"


No comments:

Post a Comment