• 选课小web最终版


    12.18

    今天完成了小web的系统,没有遇到问题,计划明天再练习一下web项目。

    下面是代码部分:

    package com.pp;
    import java.sql.*;
    public class DBUtil{
    private DBUtil() {}
    static {
    try {
    Class.forName("com.mysql.jdbc.Driver");
    }catch(ClassNotFoundException e) {
    e.printStackTrace();
    }
    }
    public static Connection getConnection() throws SQLException{
    return DriverManager.getConnection("jdbc:mysql://localhost:3306/shujuku?serverTimezone=UTC&useUnicode=true&zeroDateTimeBehavior=convertToNull&autoReconnect=true&characterEncoding=utf-8","root","123456");
    }
    public static void close(Connection conn,Statement ps,ResultSet rs) {
    if(rs!=null) {
    try {
    rs.close();
    }catch(SQLException s) {
    s.printStackTrace();
    }
    }
    if(ps!=null) {
    try {
    ps.close();
    }catch(SQLException s) {
    s.printStackTrace();
    }
    }
    if(conn!=null) {
    try {
    conn.close();
    }catch(SQLException s) {
    s.printStackTrace();
    }
    }
    }
    }

    package com.pp;
    public class kecheng {
    private String name;
    private String people;
    private String place;
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    public String getPeople() {
    return people;
    }
    public void setPeople(String people) {
    this.people = people;
    }
    public String getPlace() {
    return place;
    }
    public void setPlace(String place) {
    this.place = place;
    }
    public kecheng(String a,String b,String c) {
    this.name=a;
    this.people=b;
    this.place=c;
    }
    public kecheng() {

    }
    }

    package com.pp;

    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.List;

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

    /**
    * Servlet implementation class servlet
    */
    @WebServlet("/servlet")
    public class servlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

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

    /**
    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    */

    private void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String people=request.getParameter("people");
    String name=request.getParameter("name");
    String place=request.getParameter("place");

    kecheng stu=new kecheng(name,people,place);
    dao L=new dao();

    response.sendRedirect("add1.jsp");L.insert(stu);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    request.setCharacterEncoding("UTF-8");
    String method=request.getParameter("method");
    if("add".equals(method)) {
    add(request,response);
    }


    }

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

    }

  • 相关阅读:
    【矩阵乘】【DP】【codevs 1305】Freda的道路
    Giraph源代码分析(九)—— Aggregators 原理解析
    Dubbo框架应用之(三)--Zookeeper注冊中心、管理控制台的安装及解说
    Oracle中对数字加汉字的排序(完好)
    PKU-2104-K-th Number
    IE下推断IE版本号的语句
    自己定义View时,用到Paint Canvas的一些温故,简单的帧动画(动画一 ,"掏粪男孩Gif"顺便再提提onWindowFocusChanged)
    <html>
    测试一个网段主机在线情况,禁ping的情况除外
    glance image-create --name "wj_js_company_img" --file a0e1c7fa-d6d3-410f-9bb5-e699e342db91 --disk-format qcow2 --container-format bare --progress --visibility public
  • 原文地址:https://www.cnblogs.com/092e/p/14169675.html
Copyright © 2020-2023  润新知