• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Retrive variable from JavaScript to JSP page

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I need to pass the content of a variable from a javascript function to a jsp page. The content of the variable is huge, so I can't send it via URL.

Thanks.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The simplest way to do is to have a hidden field, textbox, on the page and assign the text value of it in jscript.
You can then use tht value in jsp or even in a servlet on form submission.

Hope this helps.
 
Tomita Militaru
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay I did it, but now I don't know how to get the content from the textarea for example. I don't have any submit button.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then how do you plan to submit the form?
 
Tomita Militaru
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Then how do you plan to submit the form?



Well there's no submit form, I'm making some operations in a javascript function by clicking on a link. From there I need to parse the result to a jsp page, thats why I needed a textarea.
I hope you understand what I mean
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you talking about getting this data to the "next" JSP, or to the JSP that resulted in the current page being displayed?

If the former, then a submit of some type has to happen in order to transition to the next JSP.

If the latter, then you need to find out a bit more about how JSP works. Perhaps this article will help.
 
Tomita Militaru
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree, i'm new to JSP. I was reading that article just now.

I have only one JSP file, all the operations are made via JavaScript.

This is the core of my JSP page:



Before that core I have put an invisible textarea which will have the result from some calculations. I need to check with JSP if the textarea is empty, if not to write/send that content somewhere. Hope this clears a bit things up.
Thanks.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read the article. What you are trying to do is impossible.

The JSP code executes on the server in order to a format an HTML page to send to the client. By the time the HTML is interpreted and the JavaScript executes, the JSP has long since done its job.

 
Tomita Militaru
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just finished reading the JSP article and now I understand my problem. I guess I'm stuck, I needed to write that result on my server, since JavaScript doesn't allow it. Any sugestions?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To get data from the client to the server requires an HTTP request. Whether that's a form submission, a link traversal or an Ajax request depends upon the nature of the page and what you want to happen.

If you want it to happen quietly, behind the scenes with no disruption to the page and under JavaScript control, that's what Ajax is for.

Or you might just want to back up a bit and re-evaluate the whole design of the page. Are you doing things the best way, or just trying to hodge-podge? You haven't given us enough context to evaluate.
 
Tomita Militaru
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help, I've redesigned my application and used serlvets + JSP, problem solved.
 
Your mind is under my control .... your will is now mine .... read this tiny ad
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic