• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading from HTML Drop-Down Menu into JSP

 
Scott Florez
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • 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:
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Scott Florez
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • 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
  • 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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!