How to pass value from javascript to java?

Published on Author bloggerthreeLeave a comment

Transferring the values between javascript and java can be done using the follow example

1)Pass value from jsp scriplet to javascript:

<% String str=”Hello World”; %>
<html>
<head>
<script language=”javascript”>

function access(){

var s=”<%=str%>”;
alert(s);
}
</script>
</head>
<body onload=”access()”>
</body>
</html>

2)Pass value from javascript to Jsp scriplet:

<script>
function get(){
var m=”Hello”;
window.location.replace(“h.jsp?mess=”+m);
}
</script>
<input type=”button” onclick=”get();” value=”click”>
<%String message=request.getParameter(“mess”);
out.println(message);
%>

Comments

comments

Leave a Reply

Your email address will not be published. Required fields are marked *