Solved

Voting servlet with java: how ?

Posted on 1998-10-22
3
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error in @AspectJ Based AOP with Spring 2 23
login form jsp example 2 50
Java array 10 63
Java List 4 41
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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 learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.

733 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