【发布时间】:2026-01-07 14:30:01
【问题描述】:
我是一名大学生,在作业方面需要帮助。我需要创建一个程序,允许用户输入 2 个会话键的数据值:艺术家和颜色。该页面需要创建 2 个基于 2 个名称:值对的会话属性。创建这些后,我需要创建另一个使用 session.getAttribute 方法查看值的页面。我相信我在使用 session.setAttribute 方法将输入数据中的值分配给会话数据时遇到了问题。
这是我目前拥有的
<!DOCTYPE html>
<html>
<head>
<title>Session Creation</title>
<link rel="stylesheet" href="css-3.css">
</head>
<body>
<div class="center">
<h1>Enter Session Information</h1>
<form action="viewSessionData.jsp" method="GET">
<table class="inline-block">
<tr><th id="th-id1" colspan="2">Session Information</th></tr>
<tr>
<td>Artist:</td>
<td><input type="text" name="artistValue"></td>
<% String artistValue = "";
session.setAttribute("artistValue", artistValue); %>
</tr>
<tr>
<td>Color:</td>
<td><input type="text" name="colorValue"></td>
<% String colorValue = "";
session.setAttribute("colorValue", colorValue); %>
</tr>
<tr>
<td></td>
<td><br><input type="submit" class="coral_color"
value="Create Session"></td>
</tr>
</table>
</form>
</div>
</body>
</html>
下面是另一个文件,viewSessionData.jsp
<!DOCTYPE html>
<html>
<head>
<title>JSP Session Tracking</title>
<link rel="stylesheet" href="css-3.css">
</head>
<%@ page import="java.util.*" %>
<body>
<div class="center">
<h1>Session Tracking</h1>
<table class="inline-block">
<tr id="th-id1">
<th>Session info</th>
<th>Value</th>
</tr>
<tr>
<td>Color</td>
<td><%= session.getAttribute("colorValue") %></td>
</tr>
<tr>
<td>Artist</td>
<td><%= session.getAttribute("artistValue") %></td>
</tr>
</table>
</div>
</body>
</html>
任何帮助将不胜感激!
【问题讨论】:
标签: java html jsp session-cookies