文件结构
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项目