个人简历管理系统(6)-登陆与注册后端实现

个人简历管理系统-登陆与注册后端实现

文件结构

文件结构

login.java

package com.resume.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.resume.bean.User;
import com.resume.dao.UserDao;


@WebServlet("/login")
public class login extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String userid = request.getParameter("user");
		String password = request.getParameter("pwd");
		User user = new UserDao().check(userid, password);
		if(user==null) {
			request.setAttribute("message", "用户名不存在或者密码错误");
			request.getRequestDispatcher("login.jsp").forward(request, response);
		}else {
			HttpSession session = request.getSession();
			session.setAttribute("id",userid);
			request.getRequestDispatcher("main.jsp").forward(request, response);
		}
	}

}

register.java

package com.resume.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.resume.bean.User;
import com.resume.dao.UserDao;

@WebServlet("/register")
public class register extends HttpServlet {
	private static final long serialVersionUID = 1L;
     
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String userid = request.getParameter("user");
		String password = request.getParameter("pwd1");
		UserDao userDao = new UserDao();
		User user = userDao.checkId(userid);
		if(user!=null) {
			request.setAttribute("message", "该用户名已存在");
			request.getRequestDispatcher("register.jsp").forward(request, response);
		}else {
			userDao.add(userid, password);
			request.setAttribute("message", "注册成功,请登录");
			request.getRequestDispatcher("login.jsp").forward(request, response);
		}
	}

}

link.html

  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>个人简历管理系统</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css">
  <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
  <script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>

header.html

<div class="jumbotron text-center" style="margin-bottom:0px;color: red;" >
  <h1>个人简历管理系统</h1>
</div>

<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
  <a class="navbar-brand" href="#">导航</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="collapsibleNavbar">
    <ul class="navbar-nav">
      <li class="nav-item">
        <a class="nav-link" href="add.jsp">添加简历</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="ResumeService?method=ViewAll">查看简历</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="updatePwd.jsp">修改密码</a>
      </li>
        <li class="nav-item">
        <a class="nav-link" href="loginout.jsp">退出登录</a>
      </li>
    </ul>
  </div>  
</nav>

main.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@include file="link.html" %>
</head>
<body>
<%@include file="header.html" %>
</body>
</html>

备注

参考博客
用eclipse创建一个javaweb项目

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值