Solved

Voting servlet with java: how ?

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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 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 …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

729 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