怎麼在多個JSP頁面之間進行參數傳遞?
需要使用JSP的內置作用域對象session.利用它的兩個方法setAttribute(),getAttribute()
下面的這個實例實現了把第一個JSP頁面的參數傳遞給第三個頁面的功能,代碼如下:
a) one.jsp
<html> <form method="get" action="two.jsp"> what's your name:<input type="text" name="username"> <input type="submit" value="submit"> </form> </html>
b) two.jsp
<html> <form method="post" action="three.jsp?pass=123456"> <% String name=request.getParameter("username"); //將name值綁定到session中 session.setAttribute("username",name); %> Your name is:<%=request.getParameter("username")%><br> what's your hobby<br> <input type="text" name="hobby"><input type="submit" value="submit"> </form> </html>
c) three.jsp
<html> your name is:<%=session.getAttribute("username")%><br> your hobby is:<%=request.getParameter("hobby")%><br> your password is:<%=request.getParameter("pass")%><br> </form> </html>
在three.jsp中通過session.getAttribute("username")得到綁定在session中的值
*