登陆逻辑:
package com.ssm.controller;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.ssm.bean.Admin;
import com.ssm.bean.Instructor;
import com.ssm.bean.StudentInfo;
import com.ssm.service.AdminService;
import com.ssm.service.InstructorService;
import com.ssm.service.StudentInfoService;
@Controller
public class LoginController {
@Autowired
private StudentInfoService studentInfoService;
@Autowired
private InstructorService instructorService;
@Autowired
private AdminService adminService;
@RequestMapping("/LoginController")
public String login(Integer id,String spwd,String validationCode,String name1,HttpSession session) {
/**
* 获取页面验证码
* */
String vccodeString= (String) session.getAttribute("vcCode");
System.out.println(id);
/**
* 判断用户如果没有输入用户名或密码 跳转(错误页面)err.jsp
* */
if(null==id || null==spwd) {
return "err";
}
/**
* 然后判断用户选择的类型是什么(即 学生or管理员or导员)
* */
/**
* 将获取的radio属性的值转为int类型方便判断数值 从而判断进入某一个页面
* */
int type= Integer.parseInt(name1);
/**
* 当type的值分别为 0 1 2 的时候 分别对其进查询操作
* 并将用户输入的值与系统查询的值进行匹配
* 如果成功则进入相应页面,若不成功则跳转错误页面(err.jsp)
* */
if(type==0) {
StudentInfo studentInfo= studentInfoService.queryStudentInfoById(id);
String pwd1=studentInfo.getSpwd();
Integer newid1=studentInfo.getId();
if(id.equals(newid1) && spwd.equals(pwd1)
&& validationCode.equals(vccodeString)) {
session.setAttribute("studentInfo", studentInfo);
return "student";
}else {
return "err";
}
}else if(type==1) {
Instructor instructor=instructorService.queryInstructorById(id);
String pwd2=instructor.getHpwd();
Integer newid2=instructor.getId();
if(id.equals(newid2) && spwd.equals(pwd2)
&& validationCode.equals(vccodeString)) {
session.setAttribute("instructor", instructor);
return "instructor";
}else {
return "err";
}
}else {
System.out.println(type);
Admin admin=adminService.queryAdminById(id);
String pwd3=admin.getApwd();
Integer newid3=admin.getId();
System.out.println("测试专用---------------------------");
System.out.println(admin);
System.out.println(pwd3);
System.out.println(newid3);
System.out.println("测试专用---------------------------");
if(id.equals(newid3) && spwd.equals(pwd3)
&& validationCode.equals(vccodeString)) {
System.out.println("测试专用---------------------------");
System.out.println("id:"+id.equals(newid3));
System.out.println("pwd:"+spwd.equals(pwd3));
System.out.println("验证码:"+validationCode.equals(vccodeString));
System.out.println("测试专用---------------------------");
session.setAttribute("admin", admin);
return "index";
}else {
return "err";
}
}
}
}
login.jsp
<%@ page language=“java” contentType=“text/html; charset=UTF-8”
pageEncoding=“UTF-8”%>
欢迎使用奖助学金管理系统
请选择以下方式登录
第三方登录:
<h3>站内登录:</h3>
<form action="LoginController">
<div class="user">
<input type="text" name="id" value="用户名" onfocus="this.value = '';"
onBlur="if (this.value == '') {this.value = '用户名';}"> <i></i>
</div>
<div class="user-in">
<input type="password" name="spwd" value="密码"
onfocus="this.value = '';"
onBlur="if (this.value == '') {this.value = 'Password';}">
<i></i>
</div>
<div class="user">
<input type="text" name="validationCode" id="validationCode"
placeholder="请输入验证码" />
</div>
<img id="validationCode_img" src="validate.jsp"> <br /> <br />
<label class="layui-form-label">职业:</label> <br /> <br />
<div class="layui-input-block">
<input type="radio" name="name1" value="0" title="学生">学生
<input type="radio" name="name1" value="1" title="教师">教师
<input type="radio" name="name1" value="2" title="管理员">管理员
</div>
<div class="keepme">
<label class="checkbox"><input type="checkbox"
name="checkbox"><i> </i> 保存登录</label>
<div class="keep-loginbutton">
<input type="submit" value="登录" />
</div>
<div class="clear"></div>
</div>
</form>
<div class="forgot">
<p>
<a href="#">忘记密码?</a>
</p>
<div class="forgot-register">
<p>
还没有注册? <a href="tips.jsp">点击注册</a>
</p>
</div>
<div class="clear"></div>
</div>
</div>
</div>
<div class="copyright">
<p>
Template by <a href="http://www.baidu.com/" target="_blank">
不会就百度 </a>
</p>
</div>
简易的实现:其中的dao service xml 各位老哥都懂就没放上去,哈哈。
有建议的话共勉学习。