• 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
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

Passing a javascript variable to JSP

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSP and JSTL has executed long before the HTML page gets sent to the browser.
 
Sheriff
Posts: 67762
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
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic