Solved

Voting servlet with java: how ?

Posted on 1998-10-22
3
308 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java and GPO 11 71
Java Loop 6 50
jar file executable 12 43
more than one jdk and one jre 1 34
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

867 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

22 Experts available now in Live!

Get 1:1 Help Now