• 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

Getting a String out of a dropdown menu

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

I'm having trouble getting a string variable out of a dropdown form that I have on one of my pages.

What I would like is for the page to store a String value locally that is based on which option in the menu is selected when the form is submitted.

ie: hello
goodbye
good morning

submit

If the user clicks submit when "hello" is selected, the page will store "hello" locally in a String value.

I need this String value to be readable in a JSP statement, if that makes sense

ie (<% user.newPage(helloStringVariable);")

If someone could show me how to do this, it'd be greatly appreciated!

Sam
 
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The value of the selected dropdown selection will post to wherever you are posting as a name/value pair. Hopefully, you are going to a Servlet and not straight to a JSP.

More info please
 
Sheriff
Posts: 67747
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

Originally posted by Sam Gardner:
the page to store a String value locally


You'll have to define what you mean by "locally".
 
Sam Gardner
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Heh, well, first to explain my background. I have one year of Java programming experience through college, and I was hired to write a frontend for some data entry that research lab on campus needed to have done using assorted undergrads (ie, needs to be simple and easy to use, and maintainable). I looked around online (I really don't have any web development experience) and stumbled upon the Sun Application Server and JSP, so I've learned enough in the last few weeks to make a web-deployable interface with a MySQL database.

So, I don't claim that anything I'm doing is remotely close to intelligent. Please phrase your suggestions accordingly.

Anyway, currently I have my app set up to go through a password verification server and then get to the actual data entry page.

At one point, I want the user to have a drop-down list of surveys that they can enter data in. I need the actual text from this list (ie survey1) to be stored on the JSP page that the user is currently on, so the JSP can call a method in a class that I have written that will output the survey's prototype (ie q1 = true or false, q2 has choices a, b, c, etc) as an HTML table.

So, they choose survey1, click submit
and a method is called like createTable(survey1) that'll output the SQL survey prototype as an HTML table.

Let me know if that makes sense, I can't imagine this should be too much trouble but I'm just having issues conceptualizing the whole concept of beans.

Sam
 
Bear Bibeault
Sheriff
Posts: 67747
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

Originally posted by Sam Gardner:
I need the actual text from this list (ie survey1) to be stored on the JSP page that the user is currently on, so the JSP can call a method in a class that I have written that will output the survey's prototype (ie q1 = true or false, q2 has choices a, b, c, etc) as an HTML table.



JSPs (and HTTP) doesn't work that way. The JSP executes on the server and sends an HTML page to the client. Any user interaction with the page at that point can have no effect on code in the JSP which executed long ago and back on the server.

Perhaps this article can give you a better handle on the JSP life-cycle and how they operate.
 
Sam Gardner
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmm, that was a good article, Bear, thanks.

Now that my original question seems a bit dumb, is there a way I can have JSP dynamically generate the contents of a frame based on the selection made in my dropdown?

I think it might work, since the frame would be dynamically generated, but I'm not sure.

Sam
 
Sam Gardner
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmm, that was a good article, Bear, thanks.

Now that my original question seems a bit dumb, is there a way I can have JSP dynamically generate the contents of a frame based on the selection made in my dropdown?

I think it might work, since the frame would be dynamically generated, but I'm not sure.

Sam
 
Sam Gardner
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmm, that was a good article, Bear, thanks.

Now that my original question seems a bit dumb, is there a way I can have JSP dynamically generate the contents of a frame based on the selection made in my dropdown?

Or, I should say, is there a way I might be able to do this without creating a separate frame for every survey.

eg: have a frame "survey prototype" that would just call my bean method and create a table based on which survey was chosen.

I think it might work, since the frame would be dynamically generated, but I'm not sure.

Sam
 
Bear Bibeault
Sheriff
Posts: 67747
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
There are a number of ways to proceed.

You could have the dropdown selection trigger a full-page submit and you could render whatever you wanted on the JSP the next time around.

Or, you could submit to an iframe that can hold the results.

Or, if you want to dynamically add the results to the current page, you could start digging into Ajax.
 
Sam Gardner
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The iFrame idea sounds just like what I need.

Thanks!
 
Sam Gardner
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the iframe idea sounds almost perfect, but...

The dynamic iframe that will be refreshed whenever the "submit" button is clicked will refresh differently for different surveys that the user has selected. How do I send the text of what the user selected to the iframe reference JSP so that it will generate the right context?

Sam
 
Bear Bibeault
Sheriff
Posts: 67747
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 update the iframe by either setting its src attribute to a URL, or by making it the target of a form submission. In either case, the seelction can be sent to the server-side resource as a request parameter.
 
Sam Gardner
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What exactly do I set the FORM ACTION =
value to if I want to just refresh my IFRAME?

I have it sending a request alright, but I can only get my form submit button to open the src of the IFRAME rather than just refresh the IFRAME.
 
Bear Bibeault
Sheriff
Posts: 67747
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
The action is independent of which window the request will be submitted to -- it will be the same no mattrer what. It's the target attribute you want to set to the name of the iframe.
 
Sam Gardner
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, that did it.

Thanks for all the help Bear.

Someone can close this topic now if they want.
 
You had your fun. Now it's time to go to jail. Thanks for your help tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic