In javascript function.....
function mywork()
{
<%String projectName="India" %>
var prjName='<%=projectName%>';
}
or
function mywork()
{
<%String projectName="India"%>
var pname;
document.getElementById( '<%=projectName%>' )=pname;
}
thus scriplet element is converted to javascript variable...
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"
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"
How to get current date in java
import java.text.SimpleDateFormat;
import java.util.Date;
Date date = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
String dd = formatter.format(date);
import java.util.Date;
Date date = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
String dd = formatter.format(date);
Subscribe to:
Comments (Atom)