File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes how can v pass javascript values to jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how can v pass javascript values to jsp" Watch "how can v pass javascript values to jsp" New topic
Author

how can v pass javascript values to jsp

Srinath R
Ranch Hand

Joined: Jun 28, 2000
Posts: 71
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
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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

Joined: Jun 28, 2000
Posts: 71
so u mean to say that with out the query string i can not send variables from javascript to jsp.
rgopi
Greenhorn

Joined: Jan 10, 2001
Posts: 9
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


Bye<BR>Gopinath
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
"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.

Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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
Bob Moranski
Ranch Hand

Joined: Nov 22, 2000
Posts: 177
Hi, why only POST but not GET?
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: how can v pass javascript values to jsp