Solved

Voting servlet with java: how ?

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet requestdispatcher include and forward differences 1 39
difference of if loops 23 62
ejb example issues 3 26
Selenium docs api java index 3 48
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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 …

837 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