簡體   English   中英

如何使用類似於JSP的Thymeleaf將表單數據從一個HTML傳遞到另一HTML?

[英]How do I pass form data from one HTML to another using Thymeleaf similar to JSP?

我剛接觸Thymleaf和Spring,並且正在學習一門使用JSP進行客戶端查看頁面的課程。 我無法使用Spring Initializr設置JSP,所以我改用Thymeleaf(我認為無論如何我最終都會使用Thymeleaf)

我的問題是,如何將表單數據從一個HTML傳遞到另一頁? 我嘗試查看文檔,然后四處搜尋並且找不到任何東西。

我已經嘗試過使用一個類來設置對象和變量(並且我知道這是一種實現方式,我最終將學習如何做到這一點),但是我只是在嘗試將數據從一種形式獲取到另一種頁面。

在JSP中,您可以執行htmlpageOne.html

<form action="processForm" method="GET">

<input type="text" name="studentID"/>
<input type="submit"/>

</form>

htmlpageTwo.html

<body>
Student ID: ${param.studentID}
</body>

使用JSP,您可以從過去的表單中調用studentID,而不必將其存儲在任何Object中,也不必創建其他任何東西。

我知道數據不會真正到任何地方也不會存儲,但僅僅是出於簡化和演示的目的,Thymeleaf有什么辦法可以做到這一點? 任何幫助或指示將不勝感激

是的,百里香支持請求參數。

https://www.thymeleaf.org/doc/articles/springmvcaccessdata.html#request-parameters

<body>
    Student ID: <span th:text="${param.studentID}" />
</body>

暫無
暫無

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

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