parent
2bbaf0539c
commit
3e55df6c44
@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="web" name="Web">
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml" />
|
||||
</descriptors>
|
||||
<webroots>
|
||||
<root url="file://$MODULE_DIR$/src/main/webapp" relative="/" />
|
||||
</webroots>
|
||||
<sourceRoots>
|
||||
<root url="file://$MODULE_DIR$/src/main/java" />
|
||||
<root url="file://$MODULE_DIR$/src/main/resources" />
|
||||
</sourceRoots>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.servlet:javax.servlet-api:4.0.1" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.7.1" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.7.1" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.7.1" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.7.1" level="project" />
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="file://$MODULE_DIR$/src/main/webapp/WEB-INF/lib" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
<jarDirectory url="file://$MODULE_DIR$/src/main/webapp/WEB-INF/lib" recursive="false" />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>day16_test</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>day16_test</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<junit.version>5.7.1</junit.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>4.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency> </dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>3.3.1</version>
|
||||
</plugin> </plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1,97 @@
|
||||
package com.example.dao;
|
||||
|
||||
import com.example.domain.Student;
|
||||
import com.example.domain.User;
|
||||
import com.example.util.DBConnection;
|
||||
import com.example.util.JDBCUtil;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class StudentDao {
|
||||
|
||||
public List<Student> queryAll(){
|
||||
List<Student> list = new ArrayList<Student>();
|
||||
|
||||
Connection conn = DBConnection.getConn();
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
String sql = "select * from student";
|
||||
|
||||
try {
|
||||
ps = conn.prepareStatement(sql);
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()){
|
||||
list.add(new Student(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4)));
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public void delById(int id){
|
||||
Connection conn = DBConnection.getConn();
|
||||
String sql = "delete from student where id = ?";
|
||||
PreparedStatement ps = null;
|
||||
|
||||
try {
|
||||
ps = conn.prepareStatement(sql);
|
||||
ps.setInt(1,id);
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
} finally {
|
||||
DBConnection.close(null,ps,conn);
|
||||
}
|
||||
}
|
||||
|
||||
public void addstudent(String id,String name,String sex,String major){
|
||||
Connection conn = DBConnection.getConn();
|
||||
String sql = "insert into student values(?,?,?,?)";
|
||||
PreparedStatement ps = null;
|
||||
try {
|
||||
ps = conn.prepareStatement(sql);
|
||||
|
||||
//给参数赋值
|
||||
ps.setString(1,id);
|
||||
ps.setString(2,name);
|
||||
ps.setString(3,sex);
|
||||
ps.setString(4,major);
|
||||
|
||||
//执行
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static Student queryById(String id){
|
||||
String sql = "select * from student where id = ?";
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
Student student = null;
|
||||
|
||||
try {
|
||||
conn = DBConnection.getConn();
|
||||
ps = conn.prepareStatement(sql);
|
||||
ps.setString(1,id);
|
||||
rs = ps.executeQuery();
|
||||
while (rs.next()){
|
||||
student = new Student(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4));
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
return student;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.example.dao;
|
||||
|
||||
import com.example.domain.User;
|
||||
import com.example.util.JDBCUtil;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
public class UserDao {
|
||||
|
||||
private JdbcTemplate template = new JdbcTemplate(JDBCUtil.getDataSource());
|
||||
|
||||
public User login(User loginUser){
|
||||
|
||||
try{
|
||||
String sql = "select * from user where username = ? and password = ?";
|
||||
User user = template.queryForObject(sql, new BeanPropertyRowMapper<>(User.class), loginUser.getUsername(), loginUser.getPassword());
|
||||
return user;
|
||||
}catch(DataAccessException e){
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.example.domain;
|
||||
|
||||
public class Student {
|
||||
private String id;
|
||||
private String name;
|
||||
private String sex;
|
||||
private String major;
|
||||
|
||||
public Student(String id, String name, String sex, String major) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.sex = sex;
|
||||
this.major = major;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSex() {
|
||||
return sex;
|
||||
}
|
||||
|
||||
public void setSex(String sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
public String getMajor() {
|
||||
return major;
|
||||
}
|
||||
|
||||
public void setMajor(String major) {
|
||||
this.major = major;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.example.domain;
|
||||
|
||||
public class User {
|
||||
private int id;
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package com.example.servlet;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
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 java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
@WebServlet("/checkCodeServlet")
|
||||
public class CheckCodeServlet extends HttpServlet {
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
|
||||
int width = 100;
|
||||
int height = 50;
|
||||
|
||||
//1.创建一对象,在内存中生成图片
|
||||
BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_3BYTE_BGR);
|
||||
|
||||
//2.美化图片
|
||||
//2.1填充背景色
|
||||
Graphics g = image.getGraphics();//画笔对象
|
||||
g.setColor(Color.PINK);//设置画笔颜色
|
||||
g.fillRect(0,0,width,height);
|
||||
|
||||
//2.2画边框
|
||||
g.setColor(Color.BLUE);
|
||||
g.drawRect(0,0,width,height);
|
||||
|
||||
String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
|
||||
//生成随机角标
|
||||
Random random = new Random();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 1 ; i <= 4 ; i++){
|
||||
//获取随机角标
|
||||
int index = random.nextInt(str.length());
|
||||
//获取随机字符
|
||||
char ch = str.charAt(index);
|
||||
|
||||
sb.append(ch);
|
||||
|
||||
//2.3写验证码
|
||||
g.drawString(String.valueOf(ch),width/5*i,height/2);
|
||||
}
|
||||
String checkCode_session = sb.toString();
|
||||
request.getSession().setAttribute("checkCode_session",checkCode_session);
|
||||
|
||||
|
||||
g.setColor(Color.GREEN);//设置画笔颜色
|
||||
Random ran = new Random();
|
||||
for(int i = 0 ; i < 5 ; i++){
|
||||
//设置两个随机坐标点
|
||||
int x1 = ran.nextInt(width);
|
||||
int y1 = ran.nextInt(height);
|
||||
|
||||
int x2 = ran.nextInt(width);
|
||||
int y2 = ran.nextInt(height);
|
||||
|
||||
//2.4画干扰线
|
||||
g.drawLine(x1,y1,x2,y2);
|
||||
}
|
||||
|
||||
//3.将图片输出到页面展示
|
||||
ImageIO.write(image,"jpg",response.getOutputStream());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
this.doGet(request,response);
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.example.servlet;
|
||||
|
||||
import com.example.dao.UserDao;
|
||||
import com.example.domain.User;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import javax.servlet.annotation.*;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
@WebServlet("/loginServlet")
|
||||
public class LoginServlet extends HttpServlet {
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
this.doPost(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
//1.设置request编码
|
||||
request.setCharacterEncoding("UTF-8");
|
||||
|
||||
//2.获取参数
|
||||
String username = request.getParameter("username");
|
||||
String password = request.getParameter("password");
|
||||
String checkCode = request.getParameter("checkCode");
|
||||
|
||||
HttpSession session = request.getSession();
|
||||
String checkCode_session = (String) session.getAttribute("checkCode_session");
|
||||
if(checkCode_session.equalsIgnoreCase(checkCode)){
|
||||
//忽略大小写进行比较
|
||||
//验证码正确
|
||||
//判断用户名和密码是否一致
|
||||
User loginUser = new User();
|
||||
loginUser.setUsername(username);
|
||||
loginUser.setPassword(password);
|
||||
|
||||
UserDao userDao = new UserDao();
|
||||
User user = userDao.login(loginUser);
|
||||
|
||||
if(user == null){
|
||||
//登陆失败
|
||||
request.setAttribute("login_error","用户名或密码错误");
|
||||
//转发到登录界面
|
||||
request.getRequestDispatcher("/login.jsp").forward(request,response);
|
||||
}else{
|
||||
//登陆成功
|
||||
session.setAttribute("user",username);
|
||||
response.sendRedirect(request.getContextPath()+"/success.jsp");
|
||||
}
|
||||
}else{
|
||||
//验证码不一致
|
||||
//储存提示信息到request
|
||||
request.setAttribute("cc_error","验证码错误");
|
||||
//转发到登录界面
|
||||
request.getRequestDispatcher("/login.jsp").forward(request,response);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.example.servlet;
|
||||
|
||||
import com.example.dao.StudentDao;
|
||||
import com.example.domain.Student;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import javax.servlet.annotation.*;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@WebServlet("/studentAddServlet")
|
||||
public class StudentAddServlet extends HttpServlet {
|
||||
|
||||
private StudentDao dao = new StudentDao();
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
this.doPost(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
//获取参数
|
||||
String id = request.getParameter("id");
|
||||
String name = request.getParameter("name");
|
||||
String sex = request.getParameter("sex");
|
||||
String major = request.getParameter("major");
|
||||
//调用dao方法修改
|
||||
dao.addstudent(id,name,sex,major);
|
||||
List<Student> list = new ArrayList<Student>();
|
||||
request.setAttribute("students",list);
|
||||
//跳转回页面列表
|
||||
request.getRequestDispatcher("stulist.jsp").forward(request,response);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.example.servlet;
|
||||
|
||||
import com.example.dao.StudentDao;
|
||||
import com.example.domain.Student;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import javax.servlet.annotation.*;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
@WebServlet("/studentDelServlet")
|
||||
public class StudentDelServlet extends HttpServlet {
|
||||
|
||||
private StudentDao dao = new StudentDao();
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
this.doPost(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
String idstr = request.getParameter("id");
|
||||
int id = Integer.parseInt(idstr);
|
||||
|
||||
//调用dap方法删除
|
||||
dao.delById(id);
|
||||
List<Student> list = dao.queryAll();
|
||||
request.setAttribute("students",list);
|
||||
//跳转回列表页面
|
||||
request.getRequestDispatcher("stulist.jsp").forward(request,response);
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.example.servlet;
|
||||
|
||||
import com.example.dao.StudentDao;
|
||||
import com.example.domain.Student;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import javax.servlet.annotation.*;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
@WebServlet("/studentListServlet")
|
||||
public class StudentListServlet extends HttpServlet {
|
||||
|
||||
private StudentDao dao = new StudentDao();
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
this.doPost(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
List<Student> list = dao.queryAll();
|
||||
request.setAttribute("students",list);
|
||||
request.getRequestDispatcher("stulist.jsp").forward(request,response);
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.example.servlet;
|
||||
|
||||
import com.example.dao.StudentDao;
|
||||
import com.example.domain.Student;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import javax.servlet.annotation.*;
|
||||
import java.io.IOException;
|
||||
|
||||
@WebServlet("/studentViewServlet")
|
||||
public class StudentViewServlet extends HttpServlet {
|
||||
|
||||
private StudentDao dao = new StudentDao();
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
this.doPost(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
String id = request.getParameter("id");
|
||||
Student student = dao.queryById(id);
|
||||
request.setAttribute("students",student);
|
||||
request.getRequestDispatcher("viewstudent.jsp").forward(request,response);
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.example.util;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class DBConnection {
|
||||
private static String url = "jdbc:mysql://localhost:3306/day14";
|
||||
private static String user = "root";
|
||||
private static String password = "root";
|
||||
|
||||
static{
|
||||
//1.加载驱动
|
||||
try{
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
}catch (ClassNotFoundException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取数据库连接对象
|
||||
* */
|
||||
|
||||
public static Connection getConn(){
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn= DriverManager.getConnection(url,user,password);
|
||||
System.out.println("连接数据库成功");
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
public static void close(ResultSet rs, PreparedStatement ps,Connection conn){
|
||||
if(rs != null){
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
if(ps != null){
|
||||
try {
|
||||
ps.close();
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
if(conn != null){
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(DBConnection.getConn());
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
driverClassName=com.mysql.jdbc.Driver
|
||||
url=jdbc:mysql:///day14
|
||||
username=root
|
||||
password=root
|
||||
initialSize=5
|
||||
maxActive=10
|
||||
maxWait=3000
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,16 @@
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>学生信息</h2>
|
||||
<form action="/day/studentAddServlet" method="post">
|
||||
<input type="text" name="id" placeholder="学号">
|
||||
<input type="text" name="name" placeholder="姓名">
|
||||
<input type="text" name="sex" placeholder="性别">
|
||||
<input type="text" name="major" placeholder="专业">
|
||||
<input type="submit" value="提交">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,33 @@
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<script>
|
||||
window.onload = function (){
|
||||
var img = document.getElementById("check");
|
||||
img.onclick = function (){
|
||||
|
||||
var date = new Date().getTime();
|
||||
img.src = "/day/checkCodeServlet?"+date;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
div{
|
||||
color: red;
|
||||
}
|
||||
</style>
|
||||
<body>
|
||||
<form method="post" action="/day/loginServlet">
|
||||
用户名:<input type="text" name="username"><br>
|
||||
密码:<input type="password" name="password"><br>
|
||||
验证码:<input type="text" name="checkCode"><br>
|
||||
<img id="check" src="/day/checkCodeServlet" /><br>
|
||||
<input type="submit" value="登录">
|
||||
</form>
|
||||
|
||||
<div>${cc_error}</div>
|
||||
<div>${login_error}</div>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,46 @@
|
||||
<%@ page import="java.util.List" %>
|
||||
<%@ page import="com.example.domain.Student" %>
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>Title</title>
|
||||
<style type="text/css">
|
||||
table{
|
||||
border:1px solid gray;
|
||||
border-collapse:collapse;
|
||||
width: 100%;
|
||||
}
|
||||
td{
|
||||
border:1px solid gray;
|
||||
}
|
||||
</style>
|
||||
<%
|
||||
List<Student> list = (List<Student>)request.getAttribute("students");
|
||||
%>
|
||||
</head>
|
||||
<body>
|
||||
<h1>学生管理系统</h1>
|
||||
<table>
|
||||
<tr>
|
||||
<td>学号</td>
|
||||
<td>姓名</td>
|
||||
<td>性别</td>
|
||||
<td>专业</td>
|
||||
<td>操作</td>
|
||||
</tr>
|
||||
<%
|
||||
for (Student s:list){
|
||||
%>
|
||||
<tr>
|
||||
<td><%=s.getId()%></td>
|
||||
<td><%=s.getName()%></td>
|
||||
<td><%=s.getSex()%></td>
|
||||
<td><%=s.getMajor()%></td>
|
||||
<td><a href="/day/studentDelServlet?id=<%=s.getId()%>">删除</a></td>
|
||||
<td><a href="/day/studentViewServlet?id=<%=s.getId()%>">查看</a></td>
|
||||
</tr>
|
||||
<%}%>
|
||||
</table>
|
||||
<a href="addstudent.jsp">添加学生</a>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,10 @@
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1><%=request.getSession().getAttribute("user")%>,欢迎回来!</h1>
|
||||
<a href="/day/studentListServlet">查看学生列表</a>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,26 @@
|
||||
<%@ page import="com.example.domain.Student" %>
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>viewstudent</title>
|
||||
</head>
|
||||
<body>
|
||||
<table>
|
||||
<tr>
|
||||
<td>学号</td>
|
||||
<td>姓名</td>
|
||||
<td>性别</td>
|
||||
<td>专业</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<%
|
||||
Student s = (Student)request.getAttribute("students");
|
||||
%>
|
||||
<td><%=s.getId()%></td>
|
||||
<td><%=s.getName()%></td>
|
||||
<td><%=s.getSex()%></td>
|
||||
<td><%=s.getMajor()%></td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,7 @@
|
||||
driverClassName=com.mysql.jdbc.Driver
|
||||
url=jdbc:mysql:///day14
|
||||
username=root
|
||||
password=root
|
||||
initialSize=5
|
||||
maxActive=10
|
||||
maxWait=3000
|
@ -0,0 +1,5 @@
|
||||
Manifest-Version: 1.0
|
||||
Created-By: IntelliJ IDEA
|
||||
Built-By: 郑旭彬
|
||||
Build-Jdk: version 1.8.0_191
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,7 @@
|
||||
driverClassName=com.mysql.jdbc.Driver
|
||||
url=jdbc:mysql:///day14
|
||||
username=root
|
||||
password=root
|
||||
initialSize=5
|
||||
maxActive=10
|
||||
maxWait=3000
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,16 @@
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>学生信息</h2>
|
||||
<form action="/day/studentAddServlet" method="post">
|
||||
<input type="text" name="id" placeholder="学号">
|
||||
<input type="text" name="name" placeholder="姓名">
|
||||
<input type="text" name="sex" placeholder="性别">
|
||||
<input type="text" name="major" placeholder="专业">
|
||||
<input type="submit" value="提交">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,33 @@
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<script>
|
||||
window.onload = function (){
|
||||
var img = document.getElementById("check");
|
||||
img.onclick = function (){
|
||||
|
||||
var date = new Date().getTime();
|
||||
img.src = "/day/checkCodeServlet?"+date;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
div{
|
||||
color: red;
|
||||
}
|
||||
</style>
|
||||
<body>
|
||||
<form method="post" action="/day/loginServlet">
|
||||
用户名:<input type="text" name="username"><br>
|
||||
密码:<input type="password" name="password"><br>
|
||||
验证码:<input type="text" name="checkCode"><br>
|
||||
<img id="check" src="/day/checkCodeServlet" /><br>
|
||||
<input type="submit" value="登录">
|
||||
</form>
|
||||
|
||||
<div>${cc_error}</div>
|
||||
<div>${login_error}</div>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,47 @@
|
||||
<%@ page import="java.util.List" %>
|
||||
<%@ page import="com.example.domain.Student" %>
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>Title</title>
|
||||
<style type="text/css">
|
||||
table{
|
||||
border:1px solid gray;
|
||||
border-collapse:collapse;
|
||||
width: 100%;
|
||||
}
|
||||
td{
|
||||
border:1px solid gray;
|
||||
}
|
||||
</style>
|
||||
<%
|
||||
List<Student> list = (List<Student>)request.getAttribute("students");
|
||||
%>
|
||||
</head>
|
||||
<body>
|
||||
<h1>学生管理系统</h1>
|
||||
<table>
|
||||
<tr>
|
||||
<td>学号</td>
|
||||
<td>姓名</td>
|
||||
<td>性别</td>
|
||||
<td>专业</td>
|
||||
<td>操作</td>
|
||||
</tr>
|
||||
<%
|
||||
for (Student s:list){
|
||||
%>
|
||||
<tr>
|
||||
<td><%=s.getId()%></td>
|
||||
<td><%=s.getName()%></td>
|
||||
<td><%=s.getSex()%></td>
|
||||
<td><%=s.getMajor()%></td>
|
||||
<td><a href="/day/studentDelServlet?id=<%=s.getId()%>">删除</a></td>
|
||||
<td><a href="/day/studentUpdServlet?id=<%=s.getId()%>">修改</a></td>
|
||||
<td><a href="/day/studentViewServlet?id=<%=s.getId()%>">查看</a></td>
|
||||
</tr>
|
||||
<%}%>
|
||||
</table>
|
||||
<a href="addstudent.jsp">添加学生</a>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,10 @@
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1><%=request.getSession().getAttribute("user")%>,欢迎回来!</h1>
|
||||
<a href="/day/studentListServlet">查看学生列表</a>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,26 @@
|
||||
<%@ page import="com.example.domain.Student" %>
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>viewstudent</title>
|
||||
</head>
|
||||
<body>
|
||||
<table>
|
||||
<tr>
|
||||
<td>学号</td>
|
||||
<td>姓名</td>
|
||||
<td>性别</td>
|
||||
<td>专业</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<%
|
||||
Student s = (Student)request.getAttribute("students");
|
||||
%>
|
||||
<td><%=s.getId()%></td>
|
||||
<td><%=s.getName()%></td>
|
||||
<td><%=s.getSex()%></td>
|
||||
<td><%=s.getMajor()%></td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in new issue