網(wǎng)站首頁 編程語言 正文
一、單個數(shù)據(jù)提交數(shù)據(jù)
jsp代碼:
<h2>1單個數(shù)據(jù)提交</h2>
<form action="${pageContext.request.contextPath}/one.action">
name<input name="myname"/><br>
age<input name="age">
<input type="submit" value="提交">
</form>
測試代碼:
@Controller
public class DataSubmitAction {
@RequestMapping("/one.action")
public String one(String myname, int age) {
System.out.println("myname=" + myname + ",age=" + (age + 10));
return "main";
}
二、對象封裝提交數(shù)據(jù)
? ? ? 【注】需要保證請求參數(shù)的名稱與實體類中成員變量名稱一致
jsp代碼:
<h2>2對象數(shù)據(jù)封裝數(shù)據(jù)提交</h2>
<form action="${pageContext.request.contextPath}/two.action">
name<input name="name"/><br>
age<input name="age"><br>
<input type="submit" value="提交">
</form>
測試代碼:
@RequestMapping("/two.action")
public String two(User user) {
System.out.println(user);
return "main";
}
三、動態(tài)占位符提交數(shù)據(jù)
? ? ? 【注】只能用于超鏈接或地址提交數(shù)據(jù),使用注解來解析
jsp代碼:
<h2>3.動態(tài)占位符提交</h2>
<a href="${pageContext.request.contextPath}/three/張三/20.avction">動態(tài)提交</a>
測試代碼:
@RequestMapping("/three/{name}/{age}.action")
public String three(@PathVariable String name, @PathVariable int age) {
System.out.println("myname=" + name + ",age=" + (age + 10));
return "main";
}
四、映射名稱不一致的時候如何提交數(shù)據(jù)
? ? ? 【注】提交請求參數(shù)與action方法的形參的名稱不一致,使用注解@RequestParam來解析
jsp代碼:
<h2>4.參數(shù)名稱不一致解決方案</h2>
<form action="${pageContext.request.contextPath}/four.action" method="post">
name<input name="name"/><br>
age<input name="age"><br>
<input type="submit" value="提交">
</form>
測試代碼:
@RequestMapping("/four.action")
public String four(@RequestParam("name") String n, @RequestParam("age") int a) {
System.out.println("myname=" + n + ",age=" + (a + 10));
return "main";
}
五、手工提取數(shù)據(jù)
jsp代碼:
<h2>5手工提取數(shù)據(jù)</h2>
<form action="${pageContext.request.contextPath}/five.action">
name<input name="name"/><br>
age<input name="age">
<input type="submit" value="提交">
</form>
測試代碼:
@RequestMapping("/five.action")
public String five(HttpServletRequest request) {
String name = request.getParameter("name");
int age = Integer.parseInt(request.getParameter("age"));
System.out.println("myname=" + name + ",age=" + (age + 10));
return "main";
}
? ? ??
原文鏈接:https://blog.csdn.net/m0_63849044/article/details/136048489
- 上一篇:沒有了
- 下一篇:沒有了
相關(guān)推薦
- 2023-01-10 Go語言defer與return執(zhí)行的先后順序詳解_Golang
- 2023-07-09 Go 數(shù)組與切片的區(qū)別
- 2022-05-31 在.NET?MAUI應(yīng)用中配置應(yīng)用生命周期事件_實用技巧
- 2023-02-15 Python?PyWebIO提升團隊效率使用介紹_python
- 2023-10-17 uniapp通過功能性編碼跳轉(zhuǎn)到原生的app頁面
- 2022-05-24 Flutter滾動組件之SingleChildScrollView使用詳解_Android
- 2023-05-07 C語言中大小端問題實例探索解決方法_C 語言
- 2023-03-20 C#?Path類---文件路徑解讀_C#教程
- 欄目分類
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支