JAVAWEB学生信息管理系统保姆级教程(增删改查+登录注册+Filter+mysql)eclipse版

这篇具有很好参考价值的文章主要介绍了JAVAWEB学生信息管理系统保姆级教程(增删改查+登录注册+Filter+mysql)eclipse版。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

布局界面:

eclipse javaweb管理系统,java,mysql,spring

 eclipse javaweb管理系统,java,mysql,spring

 文章来源地址https://www.toymoban.com/news/detail-519548.html

Login.css 

@charset "UTF-8";
html{   
    width: 100%;   
    height: 100%;   
    overflow: hidden;   
    font-style: sans-serif;   
}   
body{   
    width: 100%;   
    height: 100%;   
    font-family: 'Open Sans',sans-serif;   
    margin: 0;   
    background-color: #808069;   
}   
#login{   
    position: absolute;   
    top: 50%;   
    left:50%;   
    margin: -150px 0 0 -150px;   
    width: 300px;   
    height: 300px;   
}   
#login h1{   
    color: #fff;   
    text-shadow:0 0 10px;   
    letter-spacing: 1px;   
    text-align: center;   
}   
h1{   
    font-size: 2em;   
    margin: 0.67em 0;   
}   
input{   
    width: 278px;   
    height: 18px;   
    margin-bottom: 10px;   
    outline: none;   
    padding: 10px;   
    font-size: 13px;   
    color: #fff;   
    text-shadow:1px 1px 1px;   
    border-top: 1px solid #312E3D;   
    border-left: 1px solid #312E3D;   
    border-right: 1px solid #312E3D;   
    border-bottom: 1px solid #56536A;   
    border-radius: 4px;   
    background-color: #2D2D3F;   
}   
.but{   
    width: 300px;   
    min-height: 20px;   
    display: block;   
    background-color: #4a77d4;   
    border: 1px solid #3762bc;   
    color: #fff;   
    padding: 9px 14px;   
    font-size: 15px;   
    line-height: normal;   
    border-radius: 5px;   
    margin: 0;   
}

Register.css

@charset "UTF-8";
html{   
    width: 100%;   
    height: 100%;   
    overflow: hidden;   
    font-style: sans-serif;   
}   
body{   
    width: 100%;   
    height: 100%;   
    font-family: 'Open Sans',sans-serif;   
    margin: 0;   
    background-color: #808A87;   
}   
#login{   
    position: absolute;   
    top: 50%;   
    left:50%;   
    margin: -150px 0 0 -150px;   
    width: 300px;   
    height: 300px;   
}   
#login h1{   
    color: #fff;   
    text-shadow:0 0 10px;   
    letter-spacing: 1px;   
    text-align: center;   
}   
h1{   
    font-size: 2em;   
    margin: 0.67em 0;   
}   
input{   
    width: 278px;   
    height: 18px;   
    margin-bottom: 10px;   
    outline: none;   
    padding: 10px;   
    font-size: 13px;   
    color: #fff;   
    text-shadow:1px 1px 1px;   
    border-top: 1px solid #312E3D;   
    border-left: 1px solid #312E3D;   
    border-right: 1px solid #312E3D;   
    border-bottom: 1px solid #56536A;   
    border-radius: 4px;   
    background-color: #2D2D3F;   
}   
.but{   
    width: 300px;   
    min-height: 20px;   
    display: block;   
    background-color: #4a77d4;   
    border: 1px solid #3762bc;   
    color: #fff;   
    padding: 9px 14px;   
    font-size: 15px;   
    line-height: normal;   
    border-radius: 5px;   
    margin: 0;   
}

login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登陆界面</title>

<link rel="stylesheet" type="text/css" href="static/Login.css"/> 
</head>
<body>

	<div id="login">  
        <h1>学生信息管理系统</h1>  
        <form method="post" action="LoginServlet">  
            <input type="text" required="required" placeholder="用户名" name="u"></input>  
            <input type="password" required="required" placeholder="密码" name="p"></input>  
            <button class="but" type="submit">登录</button>  
            <label for="password">
            没有账号请
            <a href="register.jsp" style="color:blue">注册</a>
            </label>
            
            <br>
            <label>
            	<%
            	String state = (String) session.getAttribute("A2");
            	session.removeAttribute("A2");
            	if(state != null){
            		out.print(state);
            	}
            	%>
            </label>
            
        </form>  
    </div>  
</body>
</html>

register.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>注册界面</title>
<link rel="stylesheet" type="text/css" href="static/Register.css"/>
</head>
<body>

	<div id="login">  
        <h1>注册</h1>  
        <form method="post" action="RegisterServlet">  
            <input type="text" required="required" placeholder="用户名" name="u"></input>  
            <input type="password" required="required" placeholder="密码" name="p"></input>  
            <button class="but" type="submit">注册</button>  
            <label for="password">
            返回
            <a href="login.jsp" style="color:blue">登录</a>界面
            </label>
            <br>
            <label>
            	<%
            	String state = (String) session.getAttribute("A1");
            	session.removeAttribute("A1");
            	if(state != null){
            		out.print(state);
            	}
            	%>
            </label>
            
        </form>  
    </div>  

</body>
</html>

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="com.bean.StudentBean" %>
    <%@ page import="java.util.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>增删改查界面</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script>
//增加
function submitit1() {
	document.form1.action = "AddStudentServlet"
	//document.form1.submit();
}
//修改
function submitit3() {
	document.form1.action = "UpdateStudentServlet"
}
//删除
function submitit2() {
	document.form2.action = "DeleteStudentServlet"
}
//查询
function submitit4() {
	document.form2.action = "SelectStudentServlet"
}

</script>
<style type="text/css">
h2{ 
	font-family:宋体; 
	font-weight:normal;
	
 }
</style>
</head>
<body>
<div class="container">
	<div class="row clearfix">
		<div class="col-md-12 column">
			<h2 class="text-center">
				学生信息管理系统
			</h2>	
		</div>
	</div>
	<div class="row clearfix">
		<div class="col-md-10 column"></div>
		<div class="col-md-2 column">
				你好!欢迎${username}&nbsp;<a href="/StudentsMessageDemo/LoginOut">退出</a>
		</div>
	</div>
	<p></p><hr style="border: 5px solid green;"/><p></p>
	<div class="row clearfix">
		<div class="col-md-8 column">
			<table class="table">
				<thead>
					<tr>
						<th>
							学号
						</th>
						<th>
							姓名
						</th>
						<th>
							班级
						</th>
						<th>
							年龄
						</th>
						<th>
							专业
						</th>
					</tr>
				</thead>
				<tbody>
				
				<%
            	ArrayList stuMessage = (ArrayList) session.getAttribute("stuMessage");
            	session.removeAttribute("stuMessage");
            	if(stuMessage != null){
            		
            		for(int i = 0;i < stuMessage.size();i++){
            			StudentBean a = (StudentBean)stuMessage.get(i);
            	%>
            	<tr class="success">
						<td>
							<%=a.getSid() %>
						</td>
						<td>
							<%=a.getSname() %>
						</td>
						<td>
							<%=a.getScls() %>
						</td>
						<td>
							<%=a.getAge() %>
						</td>
						<td>
							<%=a.getMajor() %>
						</td>
					</tr>
            	
            	<%
            		}
            	}
            	%>
				
				</tbody>
			</table>
		</div>
		<div class="col-md-4 column">
			<form class="form-horizontal" role="form" name="form1" method="post">
				<div class="form-group">
					 <label for="inputEmail31" class="col-sm-2 control-label">学号</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" id="inputEmail31" name="sid" />
					</div>
				</div>
				<div class="form-group">
					 <label for="inputPassword32" class="col-sm-2 control-label">姓名</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" id="inputPassword32" name="sname" />
					</div>
				</div>
				<div class="form-group">
					 <label for="inputPassword33" class="col-sm-2 control-label">班级</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" id="inputPassword33" name="scls" />
					</div>
				</div>
				<div class="form-group">
					 <label for="inputPassword34" class="col-sm-2 control-label">年龄</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" id="inputPassword34" name="age" />
					</div>
				</div>
				<div class="form-group">
					 <label for="inputPassword35" class="col-sm-2 control-label">专业</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" id="inputPassword35" name="major" />
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-offset-2 col-sm-10">
						 <button type="submit" class="btn btn-default" onclick="submitit1()">添加学生信息</button>
						 <button type="submit" class="btn btn-default" onclick="submitit3()">更改学生信息</button>
						 <br><br>
						 <%
            	String state = (String) session.getAttribute("B2");
            	session.removeAttribute("B2");
            	if(state != null){
            		out.print(state);
            	}
            	%>
						 
					</div>
				</div>
			</form>
			<form class="form-horizontal" role="form" name="form2" method="post">
				<div class="form-group">
					 <label for="inputEmail36" class="col-sm-2 control-label">学号</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" id="inputEmail36" name="sid" />
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-offset-2 col-sm-10">
						 <button type="submit" class="btn btn-default" onclick="submitit2()">删除学生信息</button>
						 <button type="submit" class="btn btn-default" onclick="submitit4()">查询学生信息</button>
						 
						 <br><br>
						 <%
            	state = (String) session.getAttribute("B1");
            	session.removeAttribute("B1");
            	if(state != null){
            		out.print(state);
            	}
            	%>	
					</div>
				</div>
			</form>	
		</div>
	</div>
</div>
</body>
</html>

StudentBean.java

package com.bean;

public class StudentBean {
	
	private String sid;
	private String sname;
	private String scls;
	private String age;
	private String major;
	public String getSid() {
		return sid;
	}
	public void setSid(String sid) {
		this.sid = sid;
	}
	public String getSname() {
		return sname;
	}
	public void setSname(String sname) {
		this.sname = sname;
	}
	public String getScls() {
		return scls;
	}
	public void setScls(String scls) {
		this.scls = scls;
	}
	public String getAge() {
		return age;
	}
	public void setAge(String age) {
		this.age = age;
	}
	public String getMajor() {
		return major;
	}
	public void setMajor(String major) {
		this.major = major;
	}

}

AdminDao.java

package com.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.util.DBUtil;

public class AdminDao {
	
	//注册
	public static boolean register(String admin,String password) {
		Connection conn = DBUtil.getConnectDb();
		String sql = "insert into auser (admin,password) values(?,?)";
		int a = 0;
		PreparedStatement stm = null; 
		boolean sta = false;
		try {
			stm = conn.prepareStatement(sql);
			stm.setString(1, admin);
			stm.setString(2, password);
			a = stm.executeUpdate();
			if(a == 0) {
				sta = false;
			}else {
				sta = true;
			}
			
			return sta;
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}	
	}

	//登录
	public static boolean login(String admin,String password) {
		Connection conn = DBUtil.getConnectDb();
		String sql = "select * from auser where admin=? and password=?";
		ResultSet rs;
		PreparedStatement stm = null; 
		boolean sta = false;
		try {
			stm = conn.prepareStatement(sql);
			stm.setString(1, admin);
			stm.setString(2, password);
			rs = stm.executeQuery();
			if(rs.next()) {
				sta = true;
			}else {
				sta = false;
			}
			
			return sta;
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}	
	}
	
}

StudentDao.java

package com.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.bean.StudentBean;
import com.util.DBUtil;

public class StudentDao {
	
	//添加
	public static boolean addStudent(String sid,String sname,String scls,String age,String major) {
		Connection conn = DBUtil.getConnectDb();
		String sql = "INSERT INTO stus VALUES(?,?,?,?,?)";
		int rs;
		PreparedStatement stm = null;
		try {
			stm = conn.prepareStatement(sql);
			stm.setString(1,sid);
			stm.setString(2,sname);
			stm.setString(3,scls);
			stm.setString(4,age);
			stm.setString(5,major);
			boolean a = false;
			rs = stm.executeUpdate();
			if(rs == 1) {
				return true;
			}else {
				return false;
			}
		}catch (SQLException e) {
			// TODO: handle exception
			e.printStackTrace();
			return false;
		}
	}
	
	//更改
	public static boolean updateStudent(String sid,String sname,String scls,String age,String major) {
		Connection conn = DBUtil.getConnectDb();
		String sql = "UPDATE stus SET sname=?,scls=?,age=?,major=? WHERE sid=?";
		int rs;
		PreparedStatement stm = null;
		try {
			stm = conn.prepareStatement(sql);
			stm.setString(1,sname);
			stm.setString(2,scls);
			stm.setString(3,age);
			stm.setString(4,major);
			stm.setString(5,sid);
			boolean a = false;
			rs = stm.executeUpdate();
			if(rs == 1) {
				return true;
			}else {
				return false;
			}
		}catch (SQLException e) {
			// TODO: handle exception
			e.printStackTrace();
			return false;
		}
	}
	
	//删除
		public static boolean deleteStudent(String sid) {
			Connection conn = DBUtil.getConnectDb();
			String sql = "DELETE FROM stus WHERE sid=?";
			int rs;
			PreparedStatement stm = null;
			try {
				stm = conn.prepareStatement(sql);
				stm.setString(1,sid);
				boolean a = false;
				rs = stm.executeUpdate();
				if(rs == 1) {
					return true;
				}else {
					return false;
				}
			}catch (SQLException e) {
				// TODO: handle exception
				e.printStackTrace();
				return false;
			}
		}
		
		//查询所有信息
		public static ArrayList getList() {
			ArrayList studentArray = new ArrayList();   
			Connection conn = DBUtil.getConnectDb();
			String sql = "SELECT * FROM stus";
			PreparedStatement stm = null;
			ResultSet rs = null;
			
				try {
					stm = conn.prepareStatement(sql);
					rs = stm.executeQuery();
					
					while (rs.next()) {
						StudentBean m = new StudentBean();
						m.setSid(rs.getString("sid"));
						m.setSname(rs.getString("sname"));
						m.setScls(rs.getString("scls"));
						m.setAge(rs.getString("age"));
						m.setMajor(rs.getString("major"));
						studentArray.add(m);
					}
					rs.close();
					stm.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return studentArray;
		}
		
		//查询单个学生信息
				public static ArrayList getList(String sid) {
					ArrayList studentArray = new ArrayList();   //建立一个数组集合
					Connection conn = DBUtil.getConnectDb();
					String sql = "SELECT * FROM stus WHERE sid=?";
					PreparedStatement stm = null;
					ResultSet rs = null;
					
						try {
							stm = conn.prepareStatement(sql);
							stm.setString(1,sid);
							rs = stm.executeQuery();
							
							while (rs.next()) {
								StudentBean m = new StudentBean();
								m.setSid(rs.getString("sid"));
								m.setSname(rs.getString("sname"));
								m.setScls(rs.getString("scls"));
								m.setAge(rs.getString("age"));
								m.setMajor(rs.getString("major"));
								studentArray.add(m);
							}
							rs.close();
							stm.close();
						} catch (SQLException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						return studentArray;
				}
}

LoginFilter.java

package com.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebFilter("/*")
public class LoginFilter implements Filter {

	@Override
	public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		HttpServletRequest request = (HttpServletRequest)req;
		HttpServletResponse response = (HttpServletResponse)res;
		HttpSession session = request.getSession();
		
		String requestURI = request.getRequestURI();
		System.out.println(requestURI);
		if(requestURI.contains("/login.jsp")
				||requestURI.contains("/LoginServlet")
				||requestURI.contains("/LoginDelete")
				||requestURI.contains("/register.jsp")
				||requestURI.contains("/Login.css")
				||requestURI.contains("/Register.css")
				||requestURI.contains("/RegisterServlet")) {
			chain.doFilter(req, res);
			return;
		}
		
		if(session.getAttribute("username")!=null) {
			chain.doFilter(req, res);
		}else{
			response.sendRedirect("login.jsp");
		}
	}

}

AddStudentServlet.java

package com.servlet;

import java.io.IOException;
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 com.dao.StudentDao;

/**
 * Servlet implementation class AddStudentServlet
 */
@WebServlet("/AddStudentServlet")
public class AddStudentServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddStudentServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		
		String id = request.getParameter("sid");
		String name = request.getParameter("sname");
		String cls = request.getParameter("scls");
		String age = request.getParameter("age");
		String major = request.getParameter("major");
		
		
		boolean a = StudentDao.addStudent(id, name, cls, age, major);
		if(a == true) {
			request.getSession().setAttribute("B2", "添加学生信息成功!");
			response.sendRedirect("/StudentsMessageDemo/index.jsp");
		}else {
			
			request.getSession().setAttribute("B2", "添加失败,请检查学号!");
			response.sendRedirect("/StudentsMessageDemo/index.jsp");
		}
		
	}

}

DeleteStudentServlet.java

package com.servlet;

import java.io.IOException;
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 com.dao.StudentDao;

/**
 * Servlet implementation class DeleteStudentServlet
 */
@WebServlet("/DeleteStudentServlet")
public class DeleteStudentServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteStudentServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		
		String id = request.getParameter("sid");
		
		boolean a = StudentDao.deleteStudent(id);

		
		if(a == true) {
			request.getSession().setAttribute("B1", "删除学生信息成功!");
			response.sendRedirect("/StudentsMessageDemo/index.jsp");
		}else {
			
			request.getSession().setAttribute("B1", "删除学生信息失败!");
			
			response.sendRedirect("/StudentsMessageDemo/index.jsp");
		}
		
	}

}

LoginOut.java

package com.servlet;

import java.io.IOException;
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 LoginOut
 */
@WebServlet("/LoginOut")
public class LoginOut extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoginOut() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		request.getSession().invalidate();
		
		response.sendRedirect("/StudentsMessageDemo/login.jsp");
	}

}

LoginServlet.java

package com.servlet;

import java.io.IOException;
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.dao.AdminDao;

/**
 * Servlet implementation class LoginServlet
 */
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoginServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		
		//获取注册信息
		String username = request.getParameter("u");
		String password = request.getParameter("p");
		
		boolean a = AdminDao.login(username, password);
		
		//登录
		
		if(a == true) {
			HttpSession session = request.getSession();

			//将username保存在session中

			session.setAttribute("username",username);
			
			response.sendRedirect("/StudentsMessageDemo/index.jsp");
		}else {
			
			request.getSession().setAttribute("A2", "账号或密码错误请重新登录!");
			
			response.sendRedirect("/StudentsMessageDemo/login.jsp");
		}
		
	}

}

RegisterServlet.java

package com.servlet;

import java.io.IOException;
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 com.dao.AdminDao;

/**
 * Servlet implementation class RegisterServlet
 */
@WebServlet("/RegisterServlet")
public class RegisterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegisterServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		
		//获取注册信息
		String username = request.getParameter("u");
		String password = request.getParameter("p");
		
		boolean a = AdminDao.register(username, password);
		
		//将注册信息存入数据库,在返回登录
		
		if(a == true) {
			
			request.getSession().setAttribute("A1", "注册账号成功!");
			response.sendRedirect("/StudentsMessageDemo/register.jsp");
		}else {
			request.getSession().setAttribute("A1", "注册账号失败!");
			response.sendRedirect("/StudentsMessageDemo/register.jsp");
		}
		
	}

}

SelectStudentServlet.java

package com.servlet;

import java.io.IOException;
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 com.dao.StudentDao;

/**
 * Servlet implementation class SelectStudentServlet
 */
@WebServlet("/SelectStudentServlet")
public class SelectStudentServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SelectStudentServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		
		//获取注册信息
		String id = request.getParameter("sid");
		
		ArrayList a;
		if(id.equals("")) {
			a = StudentDao.getList();
			request.getSession().setAttribute("B1", "查询学生信息成功!");
		}else {
			a = StudentDao.getList(id);
			
		}
		request.getSession().setAttribute("stuMessage", a);
		//System.out.println(a);
		response.sendRedirect("/StudentsMessageDemo/index.jsp");
	}

}

UpdateStudentServlet.java

package com.servlet;

import java.io.IOException;
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 com.dao.StudentDao;

/**
 * Servlet implementation class UpdateStudentServlet
 */
@WebServlet("/UpdateStudentServlet")
public class UpdateStudentServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateStudentServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		
		//获取注册信息
		String id = request.getParameter("sid");
		String name = request.getParameter("sname");
		String cls = request.getParameter("scls");
		String age = request.getParameter("age");
		String major = request.getParameter("major");
		
		boolean a = StudentDao.updateStudent(id, name, cls, age, major);

		//登录
		
		if(a == true) {
			request.getSession().setAttribute("B2", "修改学生信息成功!");
			response.sendRedirect("/StudentsMessageDemo/index.jsp");
		}else {
			
			request.getSession().setAttribute("B2", "修改失败,请检查学号!");
			
			response.sendRedirect("/StudentsMessageDemo/index.jsp");
		}
		
	}

}

DBUtil.java

package com.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUtil {
	
	public static String url="jdbc:mysql://localhost:3306/students?serverTimezone=UTC&useSSL=true&characterEncoding=utf-8";
	public static String username="root";
	public static String password="";//密码根据自己的自行添加

	static {
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} 
		catch (Exception e) {
			System.out.println(e);
		}
	}

	public static Connection getConnectDb() {
		Connection conn = null;
		try {
			System.out.println("正在连接数据库....");
			conn=DriverManager.getConnection(url,username,password);
			System.out.println("连接成功");
		} 
		catch (SQLException  e) {
			System.out.println(e);
		}
		return conn;
	}
	
}

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
  <display-name>StudentsMessageDemo</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    <welcome-file>default.htm</welcome-file>
  </welcome-file-list>
  
<filter>
	<filter-name>LoginFilter</filter-name>
	<filter-class>com.filter.LoginFilter</filter-class>
</filter>
<filter-mapping>
	<filter-name>LoginFilter</filter-name>
	<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

数据库:

eclipse javaweb管理系统,java,mysql,spring

 eclipse javaweb管理系统,java,mysql,spring

最终效果图:

登陆界面

eclipse javaweb管理系统,java,mysql,spring

注册界面 

eclipse javaweb管理系统,java,mysql,spring

主界面 

eclipse javaweb管理系统,java,mysql,spring

 

到了这里,关于JAVAWEB学生信息管理系统保姆级教程(增删改查+登录注册+Filter+mysql)eclipse版的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • javaweb入门版学生信息管理系统-增删改查+JSP+Jstl+El

    dao    servlet 部分。。。 

    2024年02月10日
    浏览(43)
  • 【JAVA】Eclipse+MYSQL数据库+JSP+基础Servlet开发JavaWeb学生信息管理系统

    目录 前言 一、搭建环境  二、功能实现、 1、   登陆界面 注册按钮 2、学生信息管理系统主界面 3、dao包  4、用户的信息展示,添加,删除,修改功能(只展示添加代码) 5、学生的信息展示,添加,删除,修改功能(只展示添加代码) 6、成绩的信息展示,添加,删除,修

    2024年02月05日
    浏览(65)
  • 【Golang项目实战】用Go写一个学生信息管理系统,真的太酷啦| 保姆级详解,附源码——建议收藏

    博主简介: 努力学习的大一在校计算机专业学生,热爱学习和创作。目前在学习和分享:数据结构、Go,Java等相关知识。 博主主页: @是瑶瑶子啦 所属专栏: Go语言核心编程 近期目标: 写好专栏的每一篇文章 学习了Go的基础语法知识,如何巩固和提升呢?跟着瑶瑶子写一个

    2024年02月02日
    浏览(56)
  • JavaWeb实现学生管理系统

    该项目是基于JavaWeb实现的学生管理系统,使用maven进行管理jar包,能够对学生信息进行增删改查,分页查询,以及实现管理员的注册、登录 数据库:MySQL 开发工具:idea 开发环境:jdk 1.8 + tomcat (1)登录注册表login (2)学生信息表student (3)创建数据表代码 (1)首页-登录界

    2024年02月03日
    浏览(48)
  • JavaWeb:(练习)十二、简单的学生管理系统

    ​ 基于练习八、练习九、练习十、练习十一的逐步练习基础上,实现了一个简单的学生管理系统。 ​ 练习八链接:JavaWeb:(练习)八、Servlet前端发送数据到后端练习 ​ 练习九链接:JavaWeb:(练习)九、Servlet数据交互、XMLHttpRequest、JSON、AJAX、AXIOS练习 ​ 练习十链接:J

    2024年02月09日
    浏览(40)
  • 基于javaweb的学生就业管理系统

    一、简介 学生基业管理系统有三个角色:管理员、企业、学生 对学生信息管理、企业信息管理、求职信息管理 后端架构:spring + springmvc + mybatis 前端架构:jsp + layui 系统环境:jdk1.8 | maven | mysql 二、主要功能    1. 登录    2. 首页    3. 学生信息管理    4. 简历信息管理  

    2024年02月03日
    浏览(43)
  • 【Jsp课设】3款基于JavaWeb的学生选课管理系统

     项目介绍:后端采用Jsp+Servlet。前端使用的是Layui的一个网站模板。开发一个在线的学生选课管理系统,用于课程设计的使用。 项目类型:JavaWeb源码  用户类型:2个角色(管理员+学生) 主要技术:Jsp+Servlet+MySQL+Jquery(前端Bootstrap或者Layui) 开发工具:Eclipse/Idea均可使用,有两

    2024年02月04日
    浏览(45)
  • Javaweb实现员工信息管理系统

    1、项目用到的技术栈 开发工具:idea 语言:java、js、html+ajax 数据库:MySQL 服务器:Tomcat 框架:mybatis、jQuery、layui 2、项目实现功能 管理员、部门负责人、员工登录和退出功能以及用户注册功能(根据不同的账号密码进入不同的页面,注册页面以及登录都有校验 管理员可查看

    2024年02月11日
    浏览(39)
  • qt实现信息管理系统(学生信息管理系统)功能更完善

    信息系统代码地址:https://gitee.com/dxl96/StdMsgSystem 本学生信息管理系统同升级改造的幅度较大,涉及到的东西对于初学者来说,可能稍显复杂,可以先移步到 https://blog.csdn.net/IT_CREATE/article/details/82027462 查看简易的系统。 本系统引入日志管理,数据库选择支持sqllite、mysql,自

    2024年02月13日
    浏览(47)
  • 基于javaweb+mysql的jsp+servlet学生成绩管理系统(管理员、教师、学生)(java+jsp+servlet+javabean+mysql+tomcat)

    基于javaweb+mysql的jsp+servlet学生成绩管理系统(管理员、教师、学生)(java+jsp+servlet+javabean+mysql+tomcat) 运行环境 Java≥8、MySQL≥5.7、Tomcat≥8 开发工具 eclipse/idea/myeclipse/sts等均可配置运行 适用 课程设计,大作业,毕业设计,项目练习,学习演示等 功能说明 管理员:个人信息、课程

    2024年02月02日
    浏览(58)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包