源码编号:F-B05
项目类型:Java web项目(开源免费)
项目名称:基于JSP+Servlet的学生信息管理系统
项目架构:B/S架构
开发语言:Java语言
前端技术:HTML、CSS、JS、JQuery等技术
后端技术:JSP、Servlet、JDBC等技术
运行环境:Win10、JDK1.8
数 据 库:MySQL5.7及以上
运行服务器:Tomcat8.0及以上
运行工具:Eclipse\MYEclipse\IDEA。
项目简介:登录注册、增删改查学生信息,可能部分功能未实现,请自行修改完善,本项目仅供参考!
项目骨架
项目部分运行截图
以下是部分代码
package com.rj.servlet;
import com.rj.service.UserService;
import com.rj.pojo.User;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
public class UserServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
String action = request.getParameter("action"); //获取action参数值
if (action == null)
action = "";
if (action.equals("userLogin")) //触发了“用户登录”请求
{
String user = request.getParameter("userID");
String pwd = request.getParameter("userPassword");
String category = request.getParameter("userCategory");
User user1 = new User();
user1.setUserID(user);
user1.setUserCategory(category);
request.getSession().setAttribute("us",user1);
try {
if(new UserService().LoginDeal(user,pwd,category)){
response.sendRedirect("main.jsp");
} else
response.sendRedirect("index.jsp");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
}
if (action.equals("userRegister")) //触发了“用户注册”请求
{
String user = request.getParameter("userID");
String pwd = request.getParameter("userPassword");
try {
if(new UserService().RegisterDeal(user,pwd)==1){
response.sendRedirect("index.jsp");
}else
response.sendRedirect("index.jsp");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
}
}
}
dao层代码
package com.rj.service;
import com.rj.pojo.User;
import java.io.UnsupportedEncodingException;
import java.sql.*;
import java.util.ArrayList;
public class UserService {
public boolean LoginDeal(String user,String pwd,String category) throws ClassNotFoundException, SQLException, IllegalAccessException, InstantiationException {
ConnDB conndb = new ConnDB();
ResultSet rs = conndb.getResult("select * from tb_user where userID=? and userPassWord=? and userCategory=?",new String[]{user,pwd,category});
if(rs.next()) {
return true;
}else {
return false;
}
}
public int RegisterDeal(String user,String pwd) throws UnsupportedEncodingException, ClassNotFoundException, SQLException, IllegalAccessException, InstantiationException {
ConnDB conndb = new ConnDB();
int rtn= conndb.executeIDU("insert into tb_user (userID,userPassword,userCategory) values(?,?,?)",new String[]{user,pwd, String.valueOf(0)});
return rtn;
}
public ArrayList FindAll() throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException {
ArrayList userList = new ArrayList();
ConnDB conndb = new ConnDB();
ResultSet rs = conndb.getResult("select * from tb_user where userCategory=?",new String[]{String.valueOf(0)});
while(rs.next()){
User user = new User();
user.setId(rs.getString("id"));
user.setUserID(rs.getString("userID"));
user.setUserPassword(rs.getString("userPassword"));
user.setUserCategory(rs.getString("userCategory"));
userList.add(user);
}
return userList;
}
public int userDel(String id) throws UnsupportedEncodingException, ClassNotFoundException, SQLException, IllegalAccessException, InstantiationException {
ConnDB conndb = new ConnDB();
int rtn= conndb.executeIDU("delete from tb_user where id=?",new String[]{id});
return rtn;
}
public int userInitPwd(String id) throws UnsupportedEncodingException, ClassNotFoundException, SQLException, IllegalAccessException, InstantiationException {
ConnDB conndb = new ConnDB();
int rtn= conndb.executeIDU("update tb_user set userPassword=123456 where id=?",new String[]{id});
return rtn;
}
public boolean userCheck(String user) throws ClassNotFoundException, SQLException, IllegalAccessException, InstantiationException {
ConnDB conndb = new ConnDB();
ResultSet rs = conndb.getResult("select * from tb_user where userID=?",new String[]{user});
if(rs.next()) {
return true;
}else {
return false;
}
}
}