1

Can anybody tell me how can i pass data from JavaScript to JSP.

I am using this code in my program.

<script language="javascript" type="text/javascript" >
var name="xyz";
</script>
<% String st="<script>document.writeln(name)</script>";
out.println(name);%>

Any suggestion would be helpful for me.

Yash
  • 182
  • 1
  • 4
rohit narang
  • 135
  • 10
  • 1
    The only way to transfer data from JavaScript running in the browser to JSP running on the server is to send an HTTP request and process it server-side. – toniedzwiedz Nov 16 '14 at 21:24
  • @Tom Can you explain me how can do this? – rohit narang Nov 16 '14 at 21:29
  • It's a broad subject. There's a number of ways you can issue an HTTP request from JavaScript, a number of ways you can send data over HTTP and a number of ways you can read this data on the server and use it. The most simple, although not the cleanest, way would be to use jQuery AJAX, put the data in a query parameter, send the request to a JSP page and [read the parameter](http://stackoverflow.com/q/1890438/1407656) – toniedzwiedz Nov 16 '14 at 21:33
  • I don't see the point in the provided sample code, just use a `document.write()`, no? –  Nov 16 '14 at 21:43
  • @Tom do you have a set of code so that i can understand what you want to say. and i cant use ajax according to my whole applications. – rohit narang Nov 16 '14 at 22:25

0 Answers0