login.jsp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  2. <html>
  3. <head>
  4. <title>学生管理系统 - 登录</title>
  5. <style>
  6. body {
  7. font-family: Arial, sans-serif;
  8. background-color: #f5f5f5;
  9. margin: 0;
  10. padding: 0;
  11. display: flex;
  12. justify-content: center;
  13. align-items: center;
  14. height: 100vh;
  15. }
  16. .login-container {
  17. background-color: white;
  18. padding: 40px;
  19. border-radius: 8px;
  20. box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  21. width: 300px;
  22. }
  23. .login-container h2 {
  24. text-align: center;
  25. color: #333;
  26. margin-bottom: 30px;
  27. }
  28. .form-group {
  29. margin-bottom: 20px;
  30. }
  31. .form-group label {
  32. display: block;
  33. margin-bottom: 5px;
  34. color: #666;
  35. }
  36. .form-group input {
  37. width: 100%;
  38. padding: 8px;
  39. border: 1px solid #ddd;
  40. border-radius: 4px;
  41. box-sizing: border-box;
  42. }
  43. .btn {
  44. width: 100%;
  45. padding: 10px;
  46. background-color: #007bff;
  47. color: white;
  48. border: none;
  49. border-radius: 4px;
  50. cursor: pointer;
  51. }
  52. .btn:hover {
  53. background-color: #0056b3;
  54. }
  55. .error {
  56. color: red;
  57. text-align: center;
  58. margin-bottom: 15px;
  59. }
  60. </style>
  61. </head>
  62. <body>
  63. <div class="login-container">
  64. <h2>学生管理系统</h2>
  65. <% if (request.getParameter("error") != null) { %>
  66. <div class="error">用户名或密码错误!</div>
  67. <% } %>
  68. <form action="${pageContext.request.contextPath}/login" method="post">
  69. <div class="form-group">
  70. <label for="username">用户名:</label>
  71. <input type="text" id="username" name="username" required>
  72. </div>
  73. <div class="form-group">
  74. <label for="password">密码:</label>
  75. <input type="password" id="password" name="password" required>
  76. </div>
  77. <button type="submit" class="btn">登录</button>
  78. </form>
  79. <!-- 简单演示用,实际项目中应该使用数据库验证 -->
  80. <script>
  81. // 演示用,实际应该在后端验证
  82. document.querySelector('form').addEventListener('submit', function(e) {
  83. const username = document.getElementById('username').value;
  84. const password = document.getElementById('password').value;
  85. // 简单验证(演示用,实际应该在后端验证)
  86. if (username === 'admin' && password === 'admin123') {
  87. // 登录成功
  88. } else {
  89. e.preventDefault();
  90. alert('用户名或密码错误!请使用 admin/admin123');
  91. }
  92. });
  93. </script>
  94. </div>
  95. </body>
  96. </html>