HttpServletRequest類既有getAttribute()方法,也有getParameter()方法,這兩個方法有以下區別:
1、HttpServletRequest類有setAttribute()方法,而沒有setParameter()方法;
2、當兩個Web組件之間為鏈接關系時,被鏈接的組件通過getParameter()方法來獲得請求參數;
例如,假定welcome.jsp和authenticate.jsp之間為鏈接關系,welcome.jsp中有以下代碼:
3、當兩個Web組件之間為轉發關系時,轉發目標組件通過getAttribute()方法來和轉發源組件共享request范圍內的數據。
假定authenticate.jsp和hello.jsp之間為轉發關系。authenticate.jsp希望向hello.jsp傳遞當前的用戶名字,如何傳遞這一數據呢?先在authenticate.jsp中調用setAttribute()方法:
新聞熱點
疑難解答