• 河北省重大需求征集系统每日进度7



    //1.改名
    package com.sici.servlet;

    import java.io.IOException;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;

    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;

    import com.sici.javabean.ty;

    //2.将删除改成类名
    /**
    * Servlet implementation class TestTuBiao
    */
    @WebServlet("/TestTuBiao")
    public class TestTuBiao extends HttpServlet{
    private static final long serialVersionUID = 1L;

    /**
    * @see HttpServlet#HttpServlet()
    */
    public TestTuBiao() {
    super();
    // TODO Auto-generated constructor stub
    }

    /**
    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    request.setCharacterEncoding("UTF-8");
    response.setContentType("text/html;charset=UTF-8");
    //声明list
    ArrayList<ty> list = new ArrayList();

    //声明缓冲区
    HttpSession session = request.getSession();

    //3.改jiaoli
    String url = "jdbc:mysql://localhost:3306/jiaoli?&useSSL=false&serverTimezone=UTC&useUnicode=yes&characterEncoding=utf8";

    Connection conn = null;
    PreparedStatement ps = null;

    try {
    Class.forName("com.mysql.cj.jdbc.Driver");
    conn = DriverManager.getConnection(url, "root", "root");

    } catch (ClassNotFoundException e) {
    response.getWriter().print("加载驱动失败");
    System.out.println("加载驱动失败");
    } catch (SQLException e) {
    response.getWriter().print("连接数据库失败");
    System.out.println("连接数据库失败");
    }
    int i=0;


    //*************************************
    //在这里写!!!!

    try {
    Statement stmt = conn.createStatement();
    //1.改sql语句
    ResultSet rs = stmt.executeQuery("select * from bigdata1");
    while (rs.next()&&i<5) {

    i++;
    String ip = rs.getString("ip");
    String num = rs.getString("num");

    list.add( new ty(ip,num) );

    }
    }catch (SQLException e) {
    response.getWriter().print("查找失败");
    System.out.println("查找失败");
    }



    int a [] = new int [5];
    String[] b = new String[5];

    for(int i1=0;i1<5;i1++)
    {
    a[i1] = Integer.parseInt(list.get(i1).getNum());
    b[i1] = list.get(i1).getIp();
    }
    session.setAttribute("a",a);
    session.setAttribute("b",b);
    request.getRequestDispatcher( "TestTuBiao.jsp").forward(request,response);
    //***************************************


    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
    }


    }

    //String id =(String) session.getAttribute("id"); //获取session中的数据
    //session.setAttribute("id",id); //将id发送到缓冲区(全局)
    //request.setAttribute("list",list); //将list发送到jsp页面
    //response.getWriter().println("<a href="mainmenu.jsp">返回主界面</a>");
    //String name=request.getParameter("name"); 从jsp中接收传来的值.
    //request.getRequestDispatcher( "mainmenu.jsp").forward(request,response); 跳转到mainmenu
    //session.removeAttribute("objectName1"); 清除缓冲区中变量"objectName1"

  • 相关阅读:
    What's New in Chrome DevTools All In One
    User Timing API All In One
    Tailwind CSS All In One
    CSS 3D rotate with mouse move All In One
    Event Timing API All In One
    Long Tasks API All In One
    js get window custom global variables All In One
    Web 前端广告落地页性能监控系统 All In One
    Element Timing API All In One
    base64编码
  • 原文地址:https://www.cnblogs.com/kongfanbing/p/14248891.html
Copyright © 2020-2023  润新知