• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing a javascript variable to JSP  RSS feed

 
Baba Bizlowsky
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

I'm trying to get a String value from my Javascript form and place it in a session attribute, so I can later get it via JSP code.

I tried this: I created a hidden form field in my form called "mainForm", in my JSP page called "mainPage.jsp":



then I placed a button later on:



Btw, the form has a bunch of events which make sure that the variable called "myString" is filled up appropriately. I checked this with an alert button and myString is definitely set correctly.

I then created a function which cunningly submitted a form to the same page, which was supposed to place this string in a request parameter supposedly allowing my JSP code to grab it and place it in a session attribute:



This function reloads all the frames, and I was hoping another frame could know freely access myString and use it in its own JSP code. Unfortunately this session attribute never gets set to anything other then null.

What am I doing wrong? And is there a more elegant solution to this trivial issue?

Thanks in advance. Cheers!

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP and JSTL has executed long before the HTML page gets sent to the browser.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have a fundamental misconception of how JSP operates. Please read this article to find out why what you are doing can't work and how JSP operates.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!