当前位置 : 主页 > 编程语言 > java >

选课小web最终版

来源:互联网 收集:自由互联 发布时间:2022-06-23
12.18 今天完成了小web的系统,没有遇到问题,计划明天再练习一下web项目。 下面是代码部分: package com.pp; import java.sql.*; public class DBUtil{ private DBUtil() {} static { try { Class.forName("com.mysql

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);
}

}


上一篇:考试售房系统
下一篇:没有了
网友评论