[英]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. 我刚接触Thymleaf和Spring,并且正在学习一门使用JSP进行客户端查看页面的课程。 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) 我无法使用Spring Initializr设置JSP,所以我改用Thymeleaf(我认为无论如何我最终都会使用Thymeleaf)
My question is, how Do i pass form data from one HTML, to another page? 我的问题是,如何将表单数据从一个HTML传递到另一页? 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 在JSP中,您可以执行htmlpageOne.html
<form action="processForm" method="GET">
<input type="text" name="studentID"/>
<input type="submit"/>
</form>
htmlpageTwo.html 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. 使用JSP,您可以从过去的表单中调用studentID,而不必将其存储在任何Object中,也不必创建其他任何东西。
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? 我知道数据不会真正到任何地方也不会存储,但仅仅是出于简化和演示的目的,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 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.