I have a jsp javabean problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • judge82
    New Member
    • Jul 2007
    • 24

    #1

    I have a jsp javabean problem

    I have two JSPs, one takes a request and the other displays the result and I am having problem with the javabean to connect the two

    here are my codes

    takes request
    Code:
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <table border="1" align="center">
    <tr>
    <td colspan="3" bgcolor="black" align="center"><font color="orange" size="3">
    Computer Voting Poll</font></td></tr>
    <tr>
    <td colspan="3" bgcolor="black" align="center"><font color="orange" size="3">
    What is your favorite computer game?
    </font></td></tr>
    <tr><td width="20%" bgcolor="black"></td>
    <td width="30%" bgcolor="black" align="left">
    
    <FORM ACTION="PollResult.jsp">
    <input type="radio" name="firstChoice" value="Oblivion" checked><font color="orange" size="2"> Oblivion </font><br>
    <input type="radio" name="secondChoice" value="starwars"><font color="orange" size="2"> Star Wars: Empire at War </font><br>
    <input type="radio" name="thirdChoice" value="finalfantasy"><font color="orange" size="2"> Final Fantasy XI: Online </font><br>
    
    
    <input type="submit" value="vote button" name="Vote">
    
    
    
    
    
    </td>
    <td bgcolor="black" width="20%"></td>
    </tr>
    
    <tr><td bgcolor="black" colspan="3" align="center"><font color="orange" size="3">
    </font><font color="white" size="3">Total Votes</font></td></tr>
    <tr><td height="15" bgcolor="orange" colspan="3"></td></tr>
    <tr><td align="left" bgcolor="black"><font color="white" size="3">0</font></td>
    <td align="left" bgcolor="black"><font color="white" size="3">Oblivion</font></td>
    <td align="center" bgcolor="black"><font color="white" size="3">0.00%</font></td>
    </tr>
    <tr><td align="left" bgcolor="black"><font color="white" size="3">0</font></td>
    <td align="left" bgcolor="black"><font color="white" size="3">Star Wars: Empire at War</font></td>
    <td align="center" bgcolor="black"><font color="white" size="3">0.00%</font></td>
    </tr>
    <tr><td align="left" bgcolor="black"><font color="white" size="3">0</font></td>
    <td align="left" bgcolor="black"><font color="white" size="3">Final Fantasy XI: Online</font></td>
    <td align="center" bgcolor="black"><font color="white" size="3">0.00%</font></td>
    </tr>
    <tr><td height="15" bgcolor="orange" colspan="3"></td></tr>
    </table>
    </body>
    </html>
    displays
    Code:
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <table border="1" align="center">
    <tr>
    <td colspan="3" bgcolor="black" align="center"><font color="orange" size="3">
    Computer Voting Poll</font></td></tr>
    <tr>
    <td colspan="3" bgcolor="black" align="center"><font color="orange" size="3">
    What is your favorite computer game?
    </font></td></tr>
    <tr><td width="20%" bgcolor="black"></td>
    <td width="30%" bgcolor="black" align="left">
    
    
    <input type="radio" name="firstChoice" value="Oblivion" checked><font color="orange" size="2"> Oblivion </font><br>
    <input type="radio" name="secondChoice" value="starwars"><font color="orange" size="2"> Star Wars: Empire at War </font><br>
    <input type="radio" name="thirdChoice" value="finalfantasy"><font color="orange" size="2"> Final Fantasy XI: Online </font><br>
    
    
    <input type="submit" value="vote button" name="Vote">
    
    
    
    
    
    </td>
    <td bgcolor="black" width="20%"></td>
    </tr>
    
      <TR><TH>
          Using jsp:setProperty</TABLE>
    <jsp:useBean id="entry" class="core.BeanPoll" />
    
    <jsp:setProperty 
        name="entry"
        property="firstChoice"
        param="firstChoice" />
    <jsp:setProperty 
        name="entry"
        property="secondChoice"
        param="secondChoice" />
    <jsp:setProperty 
        name="entry"
        property="thirdChoice"
        param="thirdChoice" />
    <BR>
    
    <tr><td bgcolor="black" colspan="3" align="center"><font color="orange" size="3">
    </font><font color="white" size="3">Total Votes</font></td></tr>
    <tr><td height="15" bgcolor="orange" colspan="3"></td></tr>
    <tr><td align="left" bgcolor="black"><font color="white" size="3">0</font></td>
    <td align="left" bgcolor="black"><font color="white" size="3">Oblivion</font></td>
    <td align="center" bgcolor="black"><font color="white" size="3"><jsp:getProperty name="entry" property="firstChoice" />%</font></td>
    </tr>
    <tr><td align="left" bgcolor="black"><font color="white" size="3">0</font></td>
    <td align="left" bgcolor="black"><font color="white" size="3">Star Wars: Empire at War</font></td>
    <td align="center" bgcolor="black"><font color="white" size="3"><jsp:getProperty name="entry" property="secondChoice" />0.00%</font></td>
    </tr>
    <tr><td align="left" bgcolor="black"><font color="white" size="3">0</font></td>
    <td align="left" bgcolor="black"><font color="white" size="3"><jsp:getProperty name="entry" property="thirdChoice" />Final Fantasy XI: Online</font></td>
    <td align="center" bgcolor="black"><font color="white" size="3">0.00%</font></td>
    </tr>
    <tr><td height="15" bgcolor="orange" colspan="3"></td></tr>
    </table>
    </body>
    </html>
    javabean
    Code:
    /*
     * BeanPoll.java
     *
     * Created on October 29, 2007, 11:18 PM
     *
     * To change this template, choose Tools | Template Manager
     * and open the template in the editor.
     */
    
    package core;
    
    /** Simple bean to illustrate the various forms
     *  of jsp:setProperty.
     *  <P>
     *  Taken from Core Servlets and JavaServer Pages 2nd Edition
     *  from Prentice Hall and Sun Microsystems Press,
     *  http://www.coreservlets.com/.
     *  &copy; 2003 Marty Hall; may be freely used or adapted.
     */
    
    public class BeanPoll {
      private String firstChoice = "unknown";
      private String secondChoice = "unknown";
      private String thirdChoice = "unknown";
    
      public String getfirstChoice() {
        return(firstChoice);
      }
    
      public void setfirstChoice(String firstChoice) {
        if (firstChoice != null) {
          this.firstChoice = firstChoice;
        } else {
          this.firstChoice = "unknown";
        }
      }
    
      public String getsecondChoice() {
        return(secondChoice);
      }
    
      public void setsecondChoice(String secondChoice) {
        if (secondChoice !=null) {
            this.secondChoice = secondChoice;
        } else {
            this.secondChoice = "unknown";
        } 
      }
    
      public String setthirdChoice() {
        return(thirdChoice);
      }
    
      public void setthirdChoice(String thirdChoice) {
        if (thirdChoice !=null) {
            this.thirdChoice = thirdChoice;
        } else {
            this.thirdChoice = "unknown";
        }
      }
      
      // In real life, replace this with database lookup.
      // See Chapters 17 and 18 for info on accessing databases
      // from servlets and JSP pages.
      
      public double getPollResult() {
        double result;
    
      public double getTotalCost() {
        return(getItemCost() * getNumItems());
      }
    }
    thanks for your time
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    What exact problem are you having? Compilation error?

    Comment

    • judge82
      New Member
      • Jul 2007
      • 24

      #3
      I sincerely believe my javabean is crappy. I am SIS person and I am too bad with java.

      I thing the first part is ok, like the set......
      but I don't know how to do the get

      i am trying to create a voting poll that has three choices. After making a choice, you can click vote and it shows you how many total votes have taken place and show the individual votes for each of the 3 choices and then show a percentage of total votes for each of the 3 choices.

      Comment

      Working...