123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <%@ page language="java" pageEncoding="UTF-8"%>
- <%
- //读取定义在web.xml文件中的全局参数DomainName,CookName
- String SSOLoginPage =request.getSession().getServletContext().getInitParameter("SSOLoginPage");
- String CookieName =request.getSession().getServletContext().getInitParameter("CookieName");
- //将大写字母变为小写并删除字符串的头尾空白符
- CookieName =CookieName.toLowerCase().trim();
- //创建一个Cookie数组对象,获得request请求发送过来的cookies
- Cookie[] cookies= request.getCookies();
- //定义登录用的Cookie,初始值为null
- Cookie loginCookie =null;
- //定义登录用的cookname,初始值为""
- String cookname ="";
- //获取此欢迎页面的url路径,同时去除字符串最后的"/"
- String url =request.getRequestURL().toString();
- url=url.substring(0,url.length() -1);
- //判断request请求发送过来的cookies是否为空
- if(cookies!=null){
- //循环cookies数组
- for(Cookie cookie:cookies){
- //将大写字母变为小写并删除字符串的头尾空白符
- cookname =cookie.getName().trim().toLowerCase();
- //匹配密钥名称
- if(CookieName.equals(cookname)){
- //如果相同,给予登录用的密钥
- loginCookie =cookie;
- //跳出循环
- break;
- }
- }
- }
- //如果循环完成,没有匹配到密钥
- if(loginCookie==null){
- //则登录失败,重定向到登录页面
- response.sendRedirect(SSOLoginPage+"?goto="+url);
- }
- %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>ssowebdemo1</title>
- <%--设置meta标签 清除页面缓存--%>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- </head>
- <style>
- #btn1 {
- background-color: #62a8ea;
- border: none;
- width: 15%;
- height: 45px;
- line-height: 45px;
- color: white;
- cursor: pointer;
- font-size: 16px;
- font-weight: bold;
- }
- #btn1:hover {
- opacity: 0.8;
- }
- </style>
- <body>
- <div align="center">
- <h1>这是第<b>一</b>个欢迎页面!</h1>
- <%--点击提交进入OutServlet进行判断--%>
- <form action="servlet/OutServlet?goto=<%=url%>" method="post">
- <button type="submit" id="btn1">退出登录</button>
- </form>
- </div>
- </body>
- </html>
|