2024/4/22
所学时间:2小时
代码行数:127行
博客园数:1篇
所学知识:编写web作业,完成了大致页面。
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<%@ page session="true" %>
<%@ page language="java" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<title>首页</title>
</head>
<body>
<%
String username = (String) session.getAttribute("username");
if (username == null) {
username = "游客";
%>
<p style="text-align: center" >欢迎您,<%= username %></p>
<% } else { %>
<p style="text-align: center">欢迎您,<%= username %></p>
<% } %>
<a href="login.jsp" style="text-align: center">登录</a>
</body>
</html>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<%@ page session="true" %>
<%@ page language="java" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<title>登录</title>
</head>
<body>
<form action="check.jsp" method="post" style="text-align: center">
用户名: <input type="text" name="username"><br>
密码: <input type="password" name="password"><br>
<input type="submit" value="登录">
</form>
</body>
</html>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<%@ page session="true" %>
<%@ page language="java" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
// 这里可以添加用户验证逻辑,这里只是简单示例
if ("niumo19".equals(username) && "123456".equals(password)) {
session.setAttribute("username", username);
response.sendRedirect("index.jsp");
} else {
response.sendRedirect("login.jsp");
}
%>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<%@ page session="true" %>
<%@ page language="java" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<title>条目内容</title>
</head>
<body>
<%
String username = (String) session.getAttribute("username");
if (username == null) {
response.sendRedirect("login.jsp");
} else {
%>
<p>欢迎您,<%= username %></p>
<!-- 此处展示条目内容 -->
<a href="index.jsp">回到首页</a>
<% } %>
</body>
</html>