• 选课小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);
    }

    }

  • 相关阅读:
    Entity Framework+SQLite+DataBaseFirst
    接口的实现方式(显示和隐示)及协变和逆变
    C#线程
    UIScrollView放大缩小图片偏移的问题
    SQL Server 2008在添加用户时弹出错误提示:此版本的 Microsoft Windows 不支持 MUST_CHANGE 选项
    jmeter的正则表达式的使用
    Linux下安装jmeter
    系统测试方案
    [ASP.NET].NET逻辑分层架构总结
    [C#]C#时间日期操作
  • 原文地址:https://www.cnblogs.com/092e/p/14169675.html
Copyright © 2020-2023  润新知