使用springboot结合vue实现sso单点登录

时间:2021-05-19

本文实例为大家分享了springboot vue实现sso单点登录的具体代码,供大家参考,具体内容如下

项目结构:

开发工具:idea, maven3
静态文件下载地址

1.pom文件:

<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://mon.LoginCheck;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import javax.servlet.http.HttpServletRequest;/** * @author xichengxml * @date 2019/2/13 17:53 */@Controllerpublic class SameOriginController { /** * cookie存在,登录成功;否则返回登录页 * @param request * @return */ @RequestMapping("/login01") public String demo01(HttpServletRequest request) { return LoginCheck.checkCookie(request) ? "success" : "login"; } @RequestMapping("/login02") public String demo02(HttpServletRequest request) { return LoginCheck.checkCookie(request) ? "success" : "login"; }}

6.登录页面及成功失败页面编写

<!-- login.html --><!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>登录</title> <script src="/js/vue.js" type="text/javascript"></script> <script src="/js/element.js" type="text/javascript"></script> <script src="/js/axios.min.js" type="text/javascript"></script> <link href="/css/element.css" rel="external nofollow" rel="stylesheet" type="text/css"/></head><body> <div id="app"> <el-input v-model="uname" placeholder="请输入用户名"></el-input> <el-input v-model="pwd" placeholder="请输入密码"></el-input> <el-button @click="submit" type="primary">登录</el-button> </div> <script> new Vue({ el: "#app", data: { uname: '', pwd: '' }, methods: { submit: function () { // 获取用户名和密码 var uname = this.uname; var pwd = this.pwd; // 发送http请求 axios.get("do-login", {params: {uname: uname, pwd: pwd}}) .then(function (response) { if(response.status == 200) { location.href = "/success"; } else { location.href = "/error"; } }) .catch(function (error) { alert("error--" + error); }) } } }); </script></body></html><!-- success.html --><!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>成功页面</title></head><body> This is success page!</body></html><!-- error.html --><!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>错误页面</title></head><body> This is error page!</body></html>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章