簡體   English   中英

如何通過 JSP 使用用戶輸入數據創建和查看會話密鑰

[英]How to create and view session keys using user input data with 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頁面?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM