Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pass javascript variable from one jsp to other

 
sruthi reddy
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 4181
21
IntelliJ IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64184
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"sruthijava reddy.java", please check your private messages for an important administrative matter.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64184
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you show me with a small example as how to use javascript variable in other page
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64184
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"sruthi reddy.", please check your private messages for an important administrative matter. Again.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64184
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64184
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic