java - 如何通过 JSP 使用用户输入数据创建和查看会话密钥
问题描述
我是一名大学生,需要帮助完成作业。我需要创建一个程序,允许用户输入 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>
任何帮助将不胜感激!
解决方案
这是你的创建属性页面,云你显示你的另一个jsp页面?
推荐阅读
- spring - 使用 spring-data-elasticsearch 时出错:3.1.0.M3
- c# - 访问类文件中的会话
- python - Image Processing Algorithm design: how to get front images from an angled camera?
- swift - Opening another screen by clicking on UICollectionViewCell
- spring - 无法创建 Spring Data jpa 存储库 bean 获取 BeanCreationException:
- elki - 如何在 Elki 中使用数组而不是 NumberVector
- c# - 更新实体中的集合会引发“无法为表中的标识列插入显式值”
- react-native - 当 redux 重新渲染包含 StackNavigator 的视图时,它会将自身重置为初始屏幕
- php - 如何将 .htaccess 文件中的条件转换为 web.config
- ruby-on-rails - Rails 中的相关内容。用户选择要关联的内容。怎么做?有很多?属于?