Poll Sample

Want to take a quick poll? This sample asks a question, lets visitors answer Yes or No, keeps a tally of the responses in a database, and then displays the results.

This sample requires a database to store the poll questions and results. If you have not already installed and configured your database for the WebSphere samples, refer to Database Configuration for instructions.

Run this sample

 


How this sample works:

This sample has:

  • A Java servlet that gets a poll question from the database and displays it on a page where the user can submit a yes or no answer
  • A servlet that reads the input data, stores it in a bean, and calls the output page
  • A JavaBean that updates the database
  • A JavaServer Page (JSP) that formats data and displays it
  • A servlet file that provides information about the servlet to the WebSphere Application Server

This sample was created with the Studio Database wizard using the 'select and update' option. It uses a relational database that stores the number of Yes and No responses for a question. Each question has a unique identifier (pollId) that is submitted as a hidden field on the input form. This ensures that the responses are added to the correct row in the database table.


How to use this sample on your web page:

To change the question, change both the text and the pollId on the input page. It's a good idea to also put the text in the question's comment field in the database.