zoukankan      html  css  js  c++  java
  • 教师投票系统(JSP+MySQL)

    display.jsp

    <%@ page language="java" import="java.sql.*" pageEncoding="gb2312"%>

     

    <html>

      

      

      <body>

     

            <table align="center">

            <caption>欢迎给老师投票</caption>

            <tr bgcolor="yellow">

            <td>编号</td>

             <td>姓名</td>

              <td>得票数</td>

               <td>投票</td>

            </tr>

         

            

            <%

            

                Class.forName("com.mysql.jdbc.Driver");

     

                Connection conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/school","root","laifu1990");

     

                Statement stat=conn.createStatement();

                 String sql="select teacherno,teachername,vote from t_vote";

                 ResultSet rs=stat.executeQuery(sql);

                 while(rs.next())

                 {

                   String teacherno=rs.getString("teacherno");

                   String teachername=rs.getString("teachername");

                   int vote=rs.getInt("vote");

                   

                %>

                 

           

             <tr bgcolor="pink">

             <td><%=teacherno %></td>

             <td><%=teachername %></td>

             <td><img  src="img/bar.jpg" width="<%=vote %>>" height="10">

             <%=vote%></td>

             <td><a href="vote.jsp?teacherno=<%=teacherno%>">投票</a></td>

             </tr>

              <%

                }

                   

              stat.close();

              conn.close();

              %>

              </table>

      </body>

    </html>

    vote.jsp

    <%@ page language="java" import="java.sql.*" pageEncoding="gb2312"%>

     

      <html>

      

      

      <body>

        <%

           String teacherno = request.getParameter("teacherno");

           Class.forName("com.mysql.jdbc.Driver");

     

          Connection conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/school","root","laifu1990");

     

           String sql="update t_vote set vote=vote+1 where teacherno=?";

           PreparedStatement ps=conn.prepareStatement(sql);

           ps.setString(1, teacherno);

           ps.executeUpdate();

           ps.close();

           conn.close();

           

         %>

        <jsp:forward page="display.jsp"></jsp:forward>

      </body>

    </html>

     

     

  • 相关阅读:
    L3-001. 凑零钱(深度优先搜索)
    L2-008. 最长对称子串
    java里面求交集并集补集
    eclipse里面ctrl+T查看继承树,左边的这些绿色红色,F,S,C代表什么意思
    树的遍历(已知前序遍历中序遍历求后序遍历,或者已知后序中序求先序)
    L1-009. N个数求和
    面试题系列之---【MySql事务隔离级别】
    我爱java系列---【待定】
    我爱java系列之---【商城项目微服务鉴权代码实现(二)—JWT在项目中的应用案例】
    我爱java系列之---【JWT实现微服务鉴权(一)】
  • 原文地址:https://www.cnblogs.com/laifu/p/3380687.html
Copyright © 2011-2022 走看看