运行环境:
- 1、mysql5.6+
- 2、tomcat8.0
- 3、jdk1.8
- 4、idea、eclipse
- 5、maven3.9
系统功能:
- 系统登录
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
<title>登录注册页面</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="${pageContext.request.contextPath }/static/login/css/login2.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${pageContext.request.contextPath }/static/login/js/jquery-2.2.3.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/static/login/js/jquery.validate.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/static/login/images/login.js"></script>
</head>
<script type="text/javascript">
$(function(){
$("#login_form").validate({
// 添加验证规则
rules: {
login_id: "required",
login_password: "required",
},
//重设提示信息
messages:{
login_id: "请输入账号",
login_password: "请填写密码",
}
});
$("#regUser").validate({
rules:{
username: {
required:true,
rangelength:[2,10]
},
tel:{
required:true,
digits:true,
rangelength:[11,11]
},
passwd:{
required:true,
rangelength:[5,18]
},
passwdRepeat: {
required:true,
equalTo: "#passwd"
}
},
messages:{
username: "请输入 2-10 位的用户名",
tel:"请输入正确的手机号",
passwd: "请输入 5-18 位的密码",
passwdRepeat: "两次密码输入不相同"
}
});
})
</script>
<style>
input.error { border: 1px solid red; }
label.error {
font-weight: bold;
font-size:1.2em;
color: #EA5200;
}
</style>
<body>
<h1>二手车公平交易平台</h1>
<div class="login" style="margin-top: 50px;">
<div class="header">
<div class="switch" id="switch">
<a class="switch_btn_focus" id="switch_qlogin" href="javascript:void(0);" tabindex="7">快速登录</a>
<a class="switch_btn" id="switch_login" href="javascript:void(0);" tabindex="8">快速注册</a>
<div class="switch_bottom" id="switch_bottom" style="position: absolute; width: 64px; left: 0px;"></div>
</div>
</div>
<div class="web_qr_login" id="web_qr_login" style="display: block; height: 235px;">
<!--登录-->
<div class="web_login" id="web_login">
<div class="login-box">
<div class="login_form">
<form action="${pageContext.request.contextPath }/loginAction" name="loginform" accept-charset="utf-8" id="login_form" class="loginForm" method="post">
<input type="hidden" name="did" value="0" />
<input type="hidden" name="to" value="log" />
<div class="uinArea" id="uinArea">
<label class="input-tips" for="u">帐号:</label>
<div class="inputOuter" id="uArea">
<input type="text" id="u" name="login_id" class="inputstyle" />
</div>
</div>
<div class="pwdArea" id="pwdArea">
<label class="input-tips" for="p">密码:</label>
<div class="inputOuter" id="pArea">
<input type="password" id="p" name="login_password" class="inputstyle" />
</div>
</div>
<!-- 显示错误,并决定是否出现找回密码控件 -->
<font color="red" size="2px">
<c:out value="${requestScope.loginError }" default=""></c:out>
</font>
<font color="red" size="2px">
<c:out value="${requestScope.loginError1 }" default=""></c:out>
</font>
<c:if test="${requestScope.loginError1 != null && requestScope.permission != 'admin'}">
<a href="${pageContext.request.contextPath }/views/findPassword.jsp">找回密码</a>
</c:if>
<div style="padding-left: 50px; margin-top: 20px;">
<input type="submit" value="登 录" style="width: 150px;" class="button_blue" />
</div>
</form>
</div>
</div>
</div>
<!--登录end-->
</div>
<!--注册-->
<div class="qlogin" id="qlogin" style="display: none;">
<div class="web_login">
<form name="form2" id="regUser" accept-charset="utf-8" action="${pageContext.request.contextPath }/register" method="post">
<input type="hidden" name="to" value="reg" />
<input type="hidden" name="did" value="0" />
<ul class="reg_form" id="reg-ul">
<li>
<label for="user" class="input-tips2">用户名:</label>
<div class="inputOuter2">
<input type="text" id="user" name="username" class="inputstyle2" />
</div>
</li>
<li>
<label for="user" class="input-tips2">注册类型:</label>
<div class="inputOuter2">
<select class="inputstyle2" name="login_permession">
<option value="user">用户</option>
<!-- <option value="shop">商家</option> -->
</select>
</div>
</li>
<li>
<label for="passwd" class="input-tips2">手机号:</label>
<div class="inputOuter2">
<input type="text" id="tel" name="tel" class="inputstyle2" />
</div>
</li>
<li>
<label for="passwd" class="input-tips2">密码:</label>
<div class="inputOuter2">
<input type="password" id="passwd" name="passwd" class="inputstyle2" />
</div>
</li>
<li>
<label for="passwd2" class="input-tips2">确认密码:</label>
<div class="inputOuter2">
<input type="password" id="passwd2" name="passwdRepeat" class="inputstyle2" />
</div>
</li>
<li>
<font color="red">${requestScope.registerTelError }</font>
<div class="inputArea">
<input type="submit" style="margin-top: 10px; margin-left: 85px;" class="button_blue" value="同意协议并注册" />
<!-- <a href="https://www.renrenche.com/zz/terms?plog_id=c8b2c377f349b5b5600218cd67e93d00" class="zcxy" target="_blank">注册协议</a> -->
<a class="zcxy" target="_blank">注册协议</a>
</div>
</li>
<div class="cl"></div>
</ul>
</form>
</div>
</div>
<!--注册end-->
</div>
<div style="margin-left:1000px">
<br>
<a href="${pageContext.request.contextPath }/indexInitAction">
<font color="white" size="3px">暂不登录</font>
</a>
</div>
</body>
</html>
package com.carSystem.action;
import com.carSystem.entity.Login;
import com.carSystem.entity.Person;
import com.carSystem.service.LoginService;
import com.carSystem.service.PersonService;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Map;
@Controller
public class LoginAction {
@Autowired
private LoginService loginService;
@Autowired
private PersonService personService;
//登录初始化页面
@RequestMapping("/loginInitAction")
public String loginInitAction(){
return "login";
}
//注册
@RequestMapping("/register")
public String register(String passwd, String username, String tel, String login_permession, Map<String, Object> map, HttpSession session){
if(personService.textTelExist(tel)){
map.put("registerTelError", "对不起,您输入的手机号码已经被注册过了。");
return "login";
}
String newId = loginService.getNewId();
loginService.addLogin(passwd, newId, login_permession);
personService.addPerson(username, newId, tel);
Login loginInfo = loginService.getRegisterLoginEntity();
if(loginInfo.getLogin_permission().equals("shop")){
session.setAttribute("shoploginSession", loginInfo);
session.setAttribute("shoploginSession_name", username);
return "/shop/index";
}else{
session.setAttribute("loginSession", loginInfo);
session.setAttribute("loginSession_name", username);
}
return "redirect:/indexInitAction";
}
//登录处理
@RequestMapping("/loginAction")
public String loginAction(Login login, Map<String, Object> map, HttpSession session){
Login queryLogin = loginService.queryLoginById(login.getLogin_id());
if(queryLogin == null){ //账号不存在
map.put("loginError", "账号或密码输入错误");
return "login";
}else if(! queryLogin.getLogin_password().equals(login.getLogin_password()) ){ //密码错误
System.out.println("---------error-------");
map.put("permission", queryLogin.getLogin_permission());
map.put("loginError1", "账号或密码输入错误");
return "login";
}else if(queryLogin.getLogin_permission().equals("admin")){ //管理员
System.out.println("---------admin-------");
session.setAttribute("adminloginSession", queryLogin);
return "admin/index";
}else if(queryLogin.getLogin_permission().equals("shop")){ //商家
System.out.println("---------shop-------");
session.setAttribute("shoploginSession", queryLogin);
session.setAttribute("shoploginSession_name", personService.queryPersonById(queryLogin.getLogin_id()).getPerson_name());
return "shop/index";
}else{ //用户
System.out.println("---------user--------");
session.setAttribute("loginSession", queryLogin);
session.setAttribute("loginSession_name", personService.queryPersonById(queryLogin.getLogin_id()).getPerson_name());
return "redirect:/indexInitAction";
}
}
//跳转到(用户或商家)主页。
@RequestMapping("/indexInitAction")
public String indexInit(HttpSession session, Map<String, Object> map){
Login login = (Login)session.getAttribute("loginSession");
if(login != null && login.getLogin_permission().equals("user") ){
Person person = personService.queryPersonById(login.getLogin_id());
session.setAttribute("loginSession_name", person.getPerson_name());
System.out.println("==========index=========" + login.getLogin_permission() + "===========");
}
return "/user/index";
}
//利用ajax确定修改后的电话号码没有被注册
@RequestMapping("/ajaxTextIdAndTel")
public void ajaxTextIdAndTel(HttpServletRequest request, HttpServletResponse response, String person_tel, String login_id) throws UnsupportedEncodingException{
response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");
boolean boolReturn = true;
Login login = loginService.queryLoginById(login_id);
if(login == null){
boolReturn = false;
}else{
Person person = personService.queryPersonById(login_id);
if( !person.getPerson_tel().equals(person_tel)){
boolReturn = false;
}
}
String json = new Gson().toJson(boolReturn);
try {
response.getWriter().print(json);
} catch (IOException e) {
e.printStackTrace();
}
}
//保存用户找回的的密码
@RequestMapping("/findSaveNewPwd")
public String findSaveNewPwd(Map<String, Object> map,Login login, HttpSession session){
loginService.saveLogin(login);
Login loginInfo = loginService.queryLoginById(login.getLogin_id());
if(loginInfo.getLogin_permission().equals("shop")){
session.setAttribute("shoploginSession", loginInfo);
}else{
session.setAttribute("loginSession", loginInfo);
}
return "redirect:/indexInitAction";
}
}
package com.carSystem.service;
import com.carSystem.dao.LoginMapper;
import com.carSystem.entity.Login;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class LoginService {
@Autowired
private LoginMapper loginMapper;
//添加时获取新的用户id
public String getNewId(){
int max;
if(loginMapper.getMaxLogin_id() == null || loginMapper.getMaxLogin_id().equals("")){
max = 1001;
}else{
max = Integer.parseInt( loginMapper.getMaxLogin_id() );
}
max++;
String newId = Integer.toString(max);
return newId;
}
//注册,添加login表
public void addLogin(String password, String id, String login_permession){
Login login = new Login();
login.setLogin_id(id);
login.setLogin_password(password);
login.setLogin_permission(login_permession);
loginMapper.addLogin(login);
}
//通过id查询login表单信息
public Login queryLoginById(String login_id){
return loginMapper.queryLoginById(login_id);
}
//获取刚刚注册的用户信息
public Login getRegisterLoginEntity(){
return queryLoginById(loginMapper.getMaxLogin_id());
}
//保存login信息(用于修改密码)
public void saveLogin(Login login){
loginMapper.saveLogin(login);
}
}
package com.carSystem.dao;
import com.carSystem.entity.Login;
import org.springframework.stereotype.Repository;
@Repository
public interface LoginMapper {
//获取最大的login_id
public String getMaxLogin_id();
//注册添加login信息
public void addLogin(Login login);
//通过id查询login表单信息
public Login queryLoginById(String login_id);
//保存login信息(用于修改密码)
public void saveLogin(Login login);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.carSystem.dao.LoginMapper">
<!-- 获取最大的login_id -->
<select id="getMaxLogin_id" resultType="java.lang.String">
select MAX(login_id) from login
</select>
<!-- 注册添加login信息 -->
<insert id="addLogin" parameterType="com.carSystem.entity.Login">
insert into login (login_id, login_password, login_permission)
values( #{login_id}, #{login_password}, #{login_permission} )
</insert>
<!-- 通过id查询login表单信息 -->
<select id="queryLoginById" resultType="com.carSystem.entity.Login" parameterType="java.lang.String">
select * from login where login_id = #{ login_id }
</select>
<!-- 保存login信息(用于修改密码)-->
<update id="saveLogin" parameterType="com.carSystem.entity.Login">
update login set login_password =#{login_password} where login_id = #{login_id}
</update>
</mapper>
package com.carSystem.entity;
/**
* 登录信息实体
* 附带:
* 与sql中对应的属性
* 无参和有参构造方法,get set方法和toString方法
*/
public class Login {
private String login_id;
private String login_password;
private String login_permission;
public Login(String login_id, String login_password, String login_permission) {
super();
this.login_id = login_id;
this.login_password = login_password;
this.login_permission = login_permission;
}
public Login() {
super();
}
public String getLogin_id() {
return login_id;
}
public void setLogin_id(String login_id) {
this.login_id = login_id;
}
public String getLogin_password() {
return login_password;
}
public void setLogin_password(String login_password) {
this.login_password = login_password;
}
public String getLogin_permission() {
return login_permission;
}
public void setLogin_permission(String login_permission) {
this.login_permission = login_permission;
}
@Override
public String toString() {
return "Login [login_id=" + login_id + ", login_password=" + login_password + ", login_permission="
+ login_permission + "]";
}
}
2. 网站首页
3. 网站商城
-
购物车
-
订单管理
-
个人中心
-
关于我们
-
管理后台
-
在售车辆管理
-
品牌管理
-
分类管理
-
推荐管理
-
订单管理
系统产出:
- 代码包
- 数据库初始化脚本