File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrive variable from JavaScript to JSP page

 
Tomita Militaru
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
rahul khanna
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then how do you plan to submit the form?
 
Tomita Militaru
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help, I've redesigned my application and used serlvets + JSP, problem solved.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic