jsp与jsp页面间的值传递与接收
生活随笔
收集整理的這篇文章主要介紹了
jsp与jsp页面间的值传递与接收
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.使用<a>標簽
傳遞值
<a href="index.jsp?name=增加數據">增加數據</a>///目標頁面/值///
接收值
<% String value=request.getParameter("name");%>?
2.使用<a>標簽或表單<from>進行兩個jsp頁面的值傳遞和接收
原理:主要是通過Servlet進行值傳遞
?
發送端:a.jsp
<a>標簽默認的提交方式為get,所以這里用到的是doGet方法。
單個值傳遞 <a href="servlet?name=啊啊啊">點擊調用doGet()方法</a>多個值傳遞 <a href="servlet?usname=root&pwd=123">點擊調用doGet()方法</a>
servlet類名?servlet類中的變量名=值&servlet類中的變量名=值///
?
?
Servlet后臺:Servlet類名.java
//在doget()方法中獲取值String name=request.getParameter("username"); String pwd=request.getParameter("password");
//將獲得數據添加到request中
request.setAttribute("name", name);
request.setAttribute("pwd", pwd) //將值傳給b.jsp
request.getRequestDispatcher("b.jsp").forward(request, response);
?
接收端:b.jsp
<%String name = (String)request.getAttribute("name"); String pwd = (String)request.getAttribute("pwd"); %>?
總結:建議每個功能對應一個Servlet類。*********************重要**************************
轉載于:https://www.cnblogs.com/XueTing/p/10701690.html
總結
以上是生活随笔為你收集整理的jsp与jsp页面间的值传递与接收的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python CSV 中查找指定字符串
- 下一篇: 小米开发出100W手机快充技术:实测逆天