获得param1后转发formdata请求把参数也带上,用代码形式展示
时间: 2023-03-06 08:38:24 浏览: 59
const param1 = 'foo';const formData = new FormData();
formData.append('param1', param1);const xhr = new XMLHttpRequest();
xhr.open('POST', '/someurl');
xhr.send(formData);
相关问题
JAVA 怎么获取formdata里的请求参数,用代码形式展示
可以使用HttpServletRequest的getParameter方法获取formdata里的请求参数,下面是一个示例代码:String param1 = request.getParameter("param1");
String param2 = request.getParameter("param2");
thymeleaf 转发后,怎么把参数带过去
在 Thymeleaf 中进行转发时,可以使用以下两种方法将参数传递给目标页面:
1. 使用 URL 参数进行传递。
在转发请求时,将参数以 URL 参数的形式附加在目标页面的 URL 后面,例如:
```
return "redirect:/targetPage?param1=value1¶m2=value2";
```
在目标页面中,可以使用 Thymeleaf 的表达式语言(EL)获取 URL 参数的值,例如:
```
<div th:text="${param.param1}"></div>
<div th:text="${param.param2}"></div>
```
2. 使用模型属性进行传递。
在转发请求时,将参数以模型属性的形式添加到 Model 对象中,例如:
```
model.addAttribute("param1", "value1");
model.addAttribute("param2", "value2");
return "redirect:/targetPage";
```
在目标页面中,可以使用 Thymeleaf 的 EL 获取模型属性的值,例如:
```
<div th:text="${param1}"></div>
<div th:text="${param2}"></div>
```
需要注意的是,第一种方法适用于简单的参数传递,而第二种方法适用于复杂的数据传递,例如对象或集合。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![java](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)