• 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

Reading from HTML Drop-Down Menu into JSP

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks. I'm am just delving into JSP, and I have a very basic question. I've been looking around the internet for a good tutorial on how to read HTML form input data into my JSP page. I really haven't found anything, and was hoping that you could provide me with some good resources. I want to have just a basic HTML drop-down menu with a SQL query executed based on the menu selection. The selection from the drop-down menu should go into the SQL query where "Shawnee" currently is. Here is my JSP code:
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The preferred (best practice) way to do things with server side java is to avoid doing any database, business, or web flow from within the JSP.

Instead, most JSP developers, these days, are responding to the request with a
servlet which makes calls to the business layer (written with plain old Java objects) which returns the results in beans or lists of beans, etcc.
Context is then forward to JSPs where JSTL and EL are used to iterate over the results and build the needed HTML for displaying the results.

If you want a very small simple example of this, I have a demo app on my site:
http://simple.souther.us
Look for SimpleMVC.

This example doesn't read from a database but it (hopefully) makes it clear where the DB operations should take place.

Also, Bear Bibeault has written an article explaining how this works.
I'll look for and post a link if he doesn't first.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
 
Scott Florez
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ben, thank you for the information. While I'm not sure I fully understand how the application works, I do have it working on my server. I will modify this architecture when working with my program to make sure that program my application "the right way."

I have one follow-up question for you, though. I'm trying to query a database from the ModelBean class using the JTDS driver, and I can't seem to figure out how to get my program to properly load the driver. Apparently sticking the jtds-1.2.jar file in WEB-INF\classes doesn't work with your example as it did with my initial JSP model. Can you let me know what I need to do to get your application to properly load JTDS? Thanks so much! Scott
 
Scott Florez
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nevermind. I made a simple mistake. It has to go in the lib folder and not the classes folder. It's working great now. Thanks so much!
 
This guy is skipping without a rope. At least, that's what this tiny ad said:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic