• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

how can v pass javascript values to jsp

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have a variable mynumber in javascript
that would be something like this
var mynumber = 10;
now i need to pass this variable into jsp variable say
int jspnumber;
how do i do this
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by srinath rammohan:
i have a variable mynumber in javascript
that would be something like this
var mynumber = 10;
now i need to pass this variable into jsp variable say
int jspnumber;
how do i do this


Javascript lives in the browser. On the other hand, Java Server Pages live in the server. The communication channel from client to server is the HTTP request. So you will have to incorporate your variable value in your request in one way or another, for example by embedding it in the request URL or using a cookie.
- Peter
 
Srinath R
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so u mean to say that with out the query string i can not send variables from javascript to jsp.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
WHat u need to do is store the variable value into a hidden field (on submit event say) and this hidden field value must be captured using request.getParameter() and assign to a Java variable.
Then u can assign this value to another Java variable .
Bye
Gopinath

Originally posted by srinath rammohan:
i have a variable mynumber in javascript
that would be something like this
var mynumber = 10;
now i need to pass this variable into jsp variable say
int jspnumber;
how do i do this


 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"rgopi",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please choose a new name which meets the requirements.
Thanks.
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by srinath rammohan:
so u mean to say that with out the query string i can not send variables from javascript to jsp.


They need not be in the query string if you use a POST request as opposed to a GET. In other words, a hidden variable in a form as mentioned above.
POST request parameters are sent in the request header. Cookies are also sent in the header and would be hidden as well.
Any of these methods would serve the purpose of sending your data to the server with the HTTP request.
- Peter
 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, why only POST but not GET?
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bob Moranski:
Hi, why only POST but not GET?


I may not have been very clear. Parameters to a GET request are included in the request URL. If you want to hide these parameters, for example so that they won't end up in bookmarks, you must use either cookies or POST requests. Both of these pass parameters in the request header, not in the URL.
- Peter
 
I am mighty! And this is a mighty small ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic