JSP 頁面傳值

來源:互聯網
上載者:User

標籤:

 使用session會話傳值並重新導向頁面
 //得到使用者提交的值 String name = request.getParameter("username"); String pwd = request.getParameter("password"); //建立HttpSessio對象 HttpSession s = request.getSession(); //將值綁定在session會話中 s.setAttribute("Sname",name); s.setAttribute("Spwd",pwd); //重新導向 response.sendRedirect("yinyu.jsp");

在yinyu.jsp頁面中得到值

//使用session會話取值
String username = (String)session.getAttribute("Sname"); String password = (String)session.getAttribute("Spwd");
或者
${Sname}; ${Spwd};
 使用request方式傳值並重新導向頁面
 //得到使用者提交的值 String name = request.getParameter("username"); String pwd = request.getParameter("password"); //將值綁定在request中 request.setAttribute("Rname",name); request.setAttribute("Rpwd",pwd); //重新導向 RequestDispatcher rd = request.getRequestDispatcher("yinyu.jsp"); rd.forward(request,response);

在yinyu.jsp頁面中得到值

 //使用request協助相關取值
String username = (String)request.getAttribute("Rname"); String password = (String)request.getAttribute("Rpwd");
或者

${Sname};
 ${Spwd};

 

setAttribute() 設定綁定屬性值setAttribute("自訂命名",要綁定的引用);
getAttribute() 取出得到屬性值getAttribute("setAttribute中的自訂命名");
sendRedirect() 重新導向跳轉頁面sendRedirect("要跳轉的頁面地址");

JSP 頁面傳值

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.