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>

     

     

  • 相关阅读:
    adb使用项目导入等
    ThreadLocal类理解
    Spring MVC MyBatis
    Spring MVC原理图
    Spring MVC返回JSON的几种方法
    Understanding REST
    链表
    存储构造题(Print Check)
    线状DP(石子归并)
    线段树(与区间有关的操作)
  • 原文地址:https://www.cnblogs.com/laifu/p/3380687.html
Copyright © 2011-2022 走看看