Solved

Voting servlet with java: how ?

Posted on 1998-10-22
3
307 Views
Last Modified: 2013-11-24
This is the second question conserning voting.

The problem is to develope a voting system on a html-page.
There are five buttons given. You select one, and your
answer will be added to a oracle-based database. For each day there will be a statitics given about the voting results.

So you see, the main idea is to carry the voting results to a database, and then bring them back to the html-page.

Any code suggestions ? Unfortunately I know java but not really well...

T.
0
Comment
Question by:kojonen
3 Comments
 
LVL 1

Expert Comment

by:borup
ID: 1226128
0
 
LVL 5

Accepted Solution

by:
msmolyak earned 100 total points
ID: 1226129
Several steps:

1. User pushes the button and the browser sends a request (GET or POST, preferably POST) to the servlet. The servlet's HttpServlet.doPost(HttpServletRequest, HttpServletResponse)  method gets invoked. The HttpServletReques object contains the information from the HTML form which you can easily obtain using ServletRequest.getParameter() methods.

2. Once you have the information inside your Java application (aka servlet) you have to store it in the database. This is a completely independent part of the problem. If you are using Oracle, you indeed need to use JDBC API and some JDBC driver (there are 4 driver types and many implementations of each type, you have to do some reading to figure out which one suits your needs better. Your task is made easier by the fact that you need a local application, not a remote applet to write to your database).  You will need to map you Java objects (corresponding to voting results) and Oracle tables where those results are stored. JDBC API allows you to connect to database and execute SQL statements among other features.

3. When you need to send the results back to the client (and normally you do it in response to the POST operation, that is why you have both request and response passed into doPost() method), you need to use JDBC to extract the results from the database, format then using HTML tags and send the result using the HttpServletResponse object. I do not think the servlet can proactively (rather than reactively) talk to the browser. The user needs to initiate an action. E.g., the user may press the button "Display statistics" and in response you will display the statistics page.

Hope this is helpful.
0
 

Author Comment

by:kojonen
ID: 1226130
Best thanks !
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
java set up 1 46
firstChar challenge 13 83
wordappend challenge 8 84
Checkbox and ListView in Android Layout 4 37
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now