簡體   English   中英

如何將記錄從一個JSP文件獲取到另一個JSP文件?

[英]How to get records from one JSP file to another JSP file?

我有兩個頁面說one.jsp和two.jsp。 告訴如何將整個詳細記錄從一頁轉移到另一頁。

one.jsp將休假名稱作為年齡記錄

       name             age 
     |  abc    |      |   8  |

     |  xyz    |      |  7   |

現在,我想在two.jsp中獲得這些詳細信息,請告訴我該怎么做。

您有兩種方法可以做到這一點。

將屬性設置為session或將屬性設置為request

session.setAttribute("SomeKey",valObj);
Object attribute = session.getAttribute("SomeKey");

要么

    req.setAttribute("SomeKey",valObj);
    Object attribute2 = req.getAttribute("SomeKey");

不要忘記投射到所需的對象。

在jsp1中使用此代碼。

session.setAttribute("user1.name","abc");
session.setAttribute("user1.age",8);
session.setAttribute("user2.name","xyz");
session.setAttribute("user2.age",7);

在jsp2中使用此代碼。

String use1name = session.getAttribute("user1.name");
int user1age = Integer.parseInt(session.getAttribute("user1.age"));
String use2name = session.getAttribute("user2.name");
int user2age = Integer.parseInt(session.getAttribute("user2.age"));

您還可以根據需要使用請求或應用程序而不是會話

用超鏈接標記創建另一個(第三)列。 創建一個如下所示的鏈接

<a href="secondJspPage.jsp?name=abc&age=8">link</a>

將在第一個JSP頁面上為每個記錄創建類似的鏈接。

當您單擊該鏈接時,您可以在下一個JSP中獲得以下價值:

暫無
暫無

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

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