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

Jamming javascript variable into the session

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

I know that because the session resides on the server javascript is client, storing javascript in the session does not make sense. However, here is my situation ...

I have a value passed into a javascript function on a jsp page. This is a comma delimted string which could potentially be very very long. I need to pass it to another jsp page. The previous design, which I am correcting, sets the long string as a parameter of a form that gets submitted. However, when the string is x characters long or greater, the info will not be passed and we will end up with a blank white screen. Therefore, it can not be part of the form as it is now because x characters or greater is allowable in our situation. That is why I would like to put it in the session so that I can scoop it up on the next jsp page. Any ideas?
 
Sheriff
Posts: 67750
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
If the form method is POST rather than GET, you shouldn't run into any length issues.

To go the session route, you'd need to use Ajax to submit the value to the server behind the scenes.
 
Greg Werner
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have attached the code. It is a POST, but I don't think it reliably fails on all browser/server combos, just the one that happens to matter I would be interest hearing more about the AJAX route. By the way, the bold line is where I am trying to stuff info into the session. It happens to execute because the authors of the code happened to also create a Java variable called sCommand in the jsp file (which does not have the correct value), how convenient.

 
Bear Bibeault
Sheriff
Posts: 67750
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
If the method is post, I don't see how you are hitting any length restrictions.

Using jQuery for Ajax (life is just too short to do Ajax "by hand"), something along the lines of:

should do the trick (assumes JSP to get the context path).

This will post back to a servlet with parameters for the name and value that the servlet can create in the session/
 
Greg Werner
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the example. We weren't using jQuery in the past, but I guess we are now as I have implemented that and downloaded the jQuery js file. Just a small question of clarification. It is my understanding that when I use jQuery.post as you have showed me, I would then reference the name as request.getParameter(name) where name is the name I have selected for my data ('gmids' was my example). Is this correct? I have sort of a double submit example which is why I was thinking session. The code I demonstrated prepares a form to be submitted so first I was trying to store that 'gmids' in a session (which is post #1 via jQuery) and then submit the generated form (post #2) which would clear the parameter I just set in jQuery post. Would you recommend I try to combine the two posts . The remained of the original function is:

 
Bear Bibeault
Sheriff
Posts: 67750
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
Sorry, can't follow all that. How about backing up and describing what you are actually trying to accomplish. It sounds like you may be over-complicating the whole thing.
 
Greg Werner
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trying to pass a long list of dynamically generated ids from one jsp to another. The page which generates the ids has its form dynamically generated. Therefore, I need to dynamically generate the form and in the process include the ids before executing a submit to navigate to the next jsp. I can not include the ids directly in the form, because there are too many and a white screen would result. I would like to pass the ids separately from the form itself because the creation of the form is so complex/involved.
 
Bear Bibeault
Sheriff
Posts: 67750
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
I still think that you are over-complicating things, but since you haven't said anything about what you are really trying to accomplish with all this, I have no suggestions for simplification.

So if:

Greg Werner wrote: The page which generates the ids has its form dynamically generated.


Why aren't you just putting the id values in the session when the form is generated? Why wait until after its been sent to the browser?

I strongly suggest we address the strategy rather than the tactics. I feel you are building a Rube Goldberg machine to do something that could be much simpler.
 
I was born with webbed fish toes. This tiny ad is my only friend:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic