index.jsp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <%@ page language="java" pageEncoding="UTF-8"%>
  2. <%
  3. //读取定义在web.xml文件中的全局参数DomainName,CookName
  4. String SSOLoginPage =request.getSession().getServletContext().getInitParameter("SSOLoginPage");
  5. String CookieName =request.getSession().getServletContext().getInitParameter("CookieName");
  6. //将大写字母变为小写并删除字符串的头尾空白符
  7. CookieName =CookieName.toLowerCase().trim();
  8. //创建一个Cookie数组对象,获得request请求发送过来的cookies
  9. Cookie[] cookies= request.getCookies();
  10. //定义登录用的Cookie,初始值为null
  11. Cookie loginCookie =null;
  12. //定义登录用的cookname,初始值为""
  13. String cookname ="";
  14. //获取此欢迎页面的url路径,同时去除字符串最后的"/"
  15. String url =request.getRequestURL().toString();
  16. url=url.substring(0,url.length() -1);
  17. //判断request请求发送过来的cookies是否为空
  18. if(cookies!=null){
  19. //循环cookies数组
  20. for(Cookie cookie:cookies){
  21. //将大写字母变为小写并删除字符串的头尾空白符
  22. cookname =cookie.getName().trim().toLowerCase();
  23. //匹配密钥名称
  24. if(CookieName.equals(cookname)){
  25. //如果相同,给予登录用的密钥
  26. loginCookie =cookie;
  27. //跳出循环
  28. break;
  29. }
  30. }
  31. }
  32. //如果循环完成,没有匹配到密钥
  33. if(loginCookie==null){
  34. //则登录失败,重定向到登录页面
  35. response.sendRedirect(SSOLoginPage+"?goto="+url);
  36. }
  37. %>
  38. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  39. <html>
  40. <head>
  41. <title>ssowebdemo1</title>
  42. <%--设置meta标签 清除页面缓存--%>
  43. <meta http-equiv="pragma" content="no-cache">
  44. <meta http-equiv="cache-control" content="no-cache">
  45. <meta http-equiv="expires" content="0">
  46. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  47. <meta http-equiv="description" content="This is my page">
  48. </head>
  49. <style>
  50. #btn1 {
  51. background-color: #62a8ea;
  52. border: none;
  53. width: 15%;
  54. height: 45px;
  55. line-height: 45px;
  56. color: white;
  57. cursor: pointer;
  58. font-size: 16px;
  59. font-weight: bold;
  60. }
  61. #btn1:hover {
  62. opacity: 0.8;
  63. }
  64. </style>
  65. <body>
  66. <div align="center">
  67. <h1>这是第<b>一</b>个欢迎页面!</h1>
  68. <%--点击提交进入OutServlet进行判断--%>
  69. <form action="servlet/OutServlet?goto=<%=url%>" method="post">
  70. <button type="submit" id="btn1">退出登录</button>
  71. </form>
  72. </div>
  73. </body>
  74. </html>