• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need Some Help Here

 
Yans Tan
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

Got to trouble you guys again. Currently I am trying to pass javascript variables to a servlet or a bean file. I understand that javascript is client based and servlets are server based. But I have read up that there are ways to pass it. Anyone can show some examples on it?

Thanks in advance

Regards
Yans
 
Stefan Evans
Bartender
Posts: 1822
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only way to get a value from the client to the server is to submit a request, and send that value as a request parameter.

Most often that is done by clicking a link / submitting a form.

With a link, you construct the URL with the parameter dynamically:
eg


With submitting a form, you normally put a hidden field onto the page (<input type="hidden") and then submit the form.

A technique that is catching on is AJAX - where you make a javascript call to submit a request to the server without reloading the whole page.
It still does a request/response, but it makes the page feel faster.

There are a few ideas.
Hope that helps,
evnafets
 
Yans Tan
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

Thanks alot I think I roughly know how to do. I will try your method. If I face any problems can I pm you?

Thanks in advance!

Regards
Yans
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Add hidden fields to your form

2. Call a javascript function when the submit button is clicked (onClick event). this javascript function should populate the hidden fields with the javascript variable values.
 
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
Originally posted by Yans Tan:
If I face any problems can I pm you?


Questions and answers should appear in the forum so that all readers may benefit.
 
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
And please read this.
 
Yans Tan
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok sorry about that I will post my questions here instead of pm.

Regards
Yans
 
abhishek gowlikar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One can pass a Java Variable to Javascript variable but reverse Is not possible.

Try to Think some other Way
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by abhishek gowlikar:
One can pass a Java Variable to Javascript variable but reverse Is not possible.

Try to Think some other Way


How about as request parameters. But I got you what you meant by saying that.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!