JavaWeb课程设计-学生信息管理系统(Jsp+Servlet+MySql

JavaWeb课程设计-学生信息管理系统(Jsp+Servlet+MySql,第1张

JavaWeb课程设计-学生信息管理系统(Jsp+Servlet+MySql
  • 用户 *** 作的DAO

*/

public interface UserDao {

}

实现持久层接口:

public class UserDaoImpl implements UserDao {

private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());

}

3. 实现业务层(Service)

编写业务层接口:

public interface UserService {

}

实现业务层接口:

public class UserServiceImpl implements UserService {

private UserDao dao = new UserDaoImpl();

}

4.实现表现层功能

编写表现层:

@WebServlet("/loginServlet")

public class LoginServlet extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

this.doPost(request, response);

}

}

5.由于表现层Servlet太多,我们可以做简单的提取

编写baseServlet类,然后由其他servlet继承

public class baseServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

try {

// 获取请求标识

String methodName = request.getParameter(“method”);

// 获取指定类的字节码对象

Class clazz = this.getClass();//这里的this指的是继承baseServlet对象

// 通过类的字节码对象获取方法的字节码对象

Method method = clazz.getMethod(methodName, HttpServletRequest.class, HttpServletResponse.class);

// 让方法执行

method.invoke(this, request, response);

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

5.编写对应的前端页面:以user_login.jsp为例

<%@ page contentType=“text/html;charset=UTF-8” language=“java” %>

<%@taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core” %>

管理员登录 管理员登录


×

${login_msg}

运行截图:

测试登录功能,发现中文乱码问题(直接继承HttpServlet不会出现,继承baseServlet会出现)

6.编写过滤器解决中文乱码问题

@WebFilter("/*")

public class CharchaterFilter implements Filter {

protected String encoding;

@Override

public void destroy() {

// TODO 自动生成的方法存根

}

@Override

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {

// TODO 自动生成的方法存根

HttpServletRequest request=(HttpServletRequest)req;

HttpServletResponse response=(HttpServletResponse)res;

String method=request.getMethod();

if(method.equalsIgnoreCase(“post”)){

request.setCharacterEncoding(“utf-8”);

}

response.setContentType(“text/html;charset=utf-8”);

chain.doFilter(request, response);

}

@Override

public void init(FilterConfig arg0) throws ServletException {

// TODO 自动生成的方法存根

}

}

7.编写列表页面,并在后端代码上实现响应的功能

<%@ page language=“java” contentType=“text/html; charset=UTF-8”

pageEncoding=“UTF-8”%>

<%@ taglib uri=“http://java.sun.com/jsp/jstl/core” prefix=“c”%>

网站后台管理

学生信息管理

    • ${user.username}
    •  注销
      • 首页
      • 学生管理
      • 班级管理
      • 课程管理
      • 关于我们
        1. 管理首页
        2. 学生管理
        3. 学生信息
        4. 添加学生

          删除选中

          编号 姓名 性别 年龄 班级 电话 邮箱

          ${student.id} ${student.name} ${student.gender} ${student.age} ${student.classno} ${student.phone} ${student.email} 修改 

          删除

          【一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义】
          
          浏览器打开:qq.cn.hn/FTf 免费领取
          

          • «

          • ${i}
          • ${i}
          • »

            共 p b . t o t a l C o u n t 条 记 录 , 共 {pb.totalCount}条记录,共 pb.totalCount条记录,共{pb.totalPage}页

            8.实现不同信息的删除修改功能,并进一步完善

            <%@ page contentType=“text/html;charset=UTF-8” language=“java” %>

            <%@taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core” %>

            修改学生信息 修改学生信息

          欢迎分享,转载请注明来源:内存溢出

          原文地址: https://outofmemory.cn/zaji/5481911.html

          (0)
          打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
          上一篇 2022-12-12
          下一篇 2022-12-13

          发表评论

          登录后才能评论

          评论列表(0条)

          保存