2 回答

TA貢獻(xiàn)2080條經(jīng)驗(yàn) 獲得超4個(gè)贊
在一個(gè)servlet里面
request.setAttribute("參數(shù)標(biāo)識(shí)符","參數(shù)值");
在另一個(gè)servlet里面request.getAttribute("參數(shù)標(biāo)識(shí)符");
可以使用這個(gè)來實(shí)現(xiàn)servlet之間的跳轉(zhuǎn)
request.getRequestDispatcher("/servlet/secondServlet").forword(request,response);
以上只是其中一種,其實(shí)方式還有很多,看你想用哪個(gè)了
方法二:使用session傳值
傳值:HttpSession session =request.getSession();
session.setAttribute("bbbb", 1111111111);
取值:session.getAttribute("bbbb");
方法三:跳轉(zhuǎn)的時(shí)候超鏈接直接傳值
傳值:RequestDispatcher rd =application.getRequestDispatcher("/queryResult.jsp?a="+000);
取值:request.getParameter("a");
綜合對(duì)比:
首先,getParameter()只能傳遞字符串,而setAttribute()/getAttribute()還可以傳遞對(duì)象
其次,getParameter方法傳遞的數(shù)據(jù),會(huì)從Web客戶端傳到Web服務(wù)器端,代表HTTP請(qǐng)求數(shù)據(jù)。而setAttribute()/getAttribute()只能是頁面發(fā)送到后臺(tái)或者Web客戶端傳到Web服務(wù)器端
- 2 回答
- 0 關(guān)注
- 1818 瀏覽
添加回答
舉報(bào)