本帖最后由 cdjlovehyt 于 2011-12-10 14:22:20 编辑

解决方案 »

  1.   

    没看懂你的bean类为什么get方法要先自加在返回。
    bean类应该和数据库对应上比较好吧
    bean 类package com;public class Poll {
        private String question;
        private int yesCount;
        private int noCount;
        public int getYesCount()
        {
            return yesCount;
        }
        public void setYesCount(int newYesCount)
        {
            this.yesCount = newYesCount;
        }
        public int getNoCount()
        {
            return noCount;
        }
        public void setNoCount(int newNoCount)
        {
            this.noCount = newNoCount;
        }
        public String getQuestion()
        {
            return question;
        }
        public void setQuestion(String newQuestion)
        {
            this.question= newQuestion;
        }}在servlet里面应该是先获取页面传过来的值
    那你的form的action就应该改成action="SqlServlet";而不应该是一个JSP页面
    package com;import java.io.IOException;
    import java.io.PrintWriter;import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;public class SqlServlet extends HttpServlet {    @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            request.setCharacterEncoding("UTF-8");//设置请求数据的字符编码格式
            //先获取页面传来的值
             String q1 = request.getParameter("RadioGroup1");
             String q2 = request.getParameter("RadioGroup2");
            String q3 = request.getParameter("RadioGroup3");
            String q3 = request.getParameter("RadioGroup4");
            //判断q1,q2,q3,q4的值是不是Yes或者No;
            if(q1.equals("Yes")){
               dao.sevePollYesById(1);
            }else{
               dao.sevePollNoById(1);
            }        //再调用对应的dao的方法来插入数据库
             //dao里面完成读取对应ID的问题,把YesCount或者NoCount读取出来,在加一,存放进去
             //最好别再JSP里面写上sql语句。         //存入数据库之后,在调用dao类的方法来读取一次完整的问题和问题的Yes和No的值
             List list = dao.loadAllQuestion();        session = request.getSession();        session.setAttribute("list",list);
             PrintWriter out = response.getWriter();
            out.println("<script> alter('提交成功');</script>");
            request.getRequestDispatcher("Exercise40_13.jsp").forward(request, response);    
            
        }
    }
    然后页面在通过C标签<html>
    <body>
        <form id="form1" name="form1" method="get" >
            <table>
              <c:froEach var="templist" item="list">
                <tr>
                    <td>${templist.question}</td>
                    <td><p>
                            <label> (Yes)${templist.YesCount}</label> <label> (No)${templist.NoCount}</label> <br />
                        </p>
                    </td>
                </tr>
            </table>
          </form>
       </body>
    </html>