简体   繁体   中英

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

I'm fairly new to Thymleaf and Spring, and I'm taking a course that is using JSP for client view pages. I couldn't set up JSP using Spring Initializr so I resorted to using Thymeleaf instead (I figured I would end up using Thymeleaf normally anyways)

My question is, how Do i pass form data from one HTML, to another page? I've tried looking at the documentation, and googling around and couldn't find anything.

I have already tried using, a class to set up the Objects, and variables (and i know this is a way of doing it, i'll eventually get to the part of learning how to do that), but I'm just trying to get data from one form to another page.

In JSP you can do this htmlpageOne.html

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

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

</form>

htmlpageTwo.html

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

Using JSP you can call the studentID from the past form without having to store it in any Object and having to create any thing else.

I know the data won't really go anywhere and isn't stored, but just for simplicity and demonstration, is there any way to do the same with Thymeleaf? any help or direction would be very much appreciated

Yes, thymeleaf supports request parameters.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM