This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes How to pass javascript variable from one jsp to other Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to pass javascript variable from one jsp to other" Watch "How to pass javascript variable from one jsp to other" New topic
Author

How to pass javascript variable from one jsp to other

sruthi reddy
Ranch Hand

Joined: Aug 03, 2008
Posts: 34
Hi
I have a situation where i need to use current jsp page javascript variable in other jsp page.This second jps page will be called by clicking on href and i need to pass javascript array to it and need to obtain the values of this array in second page.suggest me how to do this.If possible send me with example.I am new to java and javascript.
Thanks
Sruthi
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4167
    
  21

You can't pass the array from javascript to JSP, as the JavaScript runs on the client machine and the JSP runs on a server on a different machine.

You can pass the values of the array to server setting them as URL parameters in the link. Your goal would be to set the URL to be something like:
http://domain/context/page.jsp?arrayName=arrayValue1&arrayName=arrayValue2&arrayName=arrayValue3 etc...

In the JSP you could then get the values from the request using
String[] values = request.getParameterValues("arrayName");


Steve
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

"sruthijava reddy.java", please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

If there's no need for the values to be available on the server, and you just need to use the data in JavaScript on the second page, you could also pass the data as a single JSON-formatted request parameter and then use eval() to reconstitute the array.
sruthi reddy
Ranch Hand

Joined: Aug 03, 2008
Posts: 34
can i use javascript popwindow for this kind of job and can i edit and save the content of javascript popup winndow.
sruthi reddy
Ranch Hand

Joined: Aug 03, 2008
Posts: 34
can you show me with a small example as how to use javascript variable in other page
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

"sruthi reddy.", please check your private messages for an important administrative matter. Again.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Originally posted by sruthijava reddy.java:
can i use javascript popwindow for this kind of job and can i edit and save the content of javascript popup winndow.
Why do you ask? Is the second page opened in another window or not?
sruthi reddy
Ranch Hand

Joined: Aug 03, 2008
Posts: 34
ya second page opens in another window and i need to edit the content of that page and update that in the database.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

As long as the original page is still loaded in the browser, the child page can access the parent via the opener variable.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to pass javascript variable from one jsp to other
 
Similar Threads
How to write retrieved data into javascript Array?
JavaScript within JSP
parameter from jsp to javascript function?
How to pass java script variable to JSP?
How to access javascript variable of one file in another jsp file