JSP復習(part 2 )
3.4.2 訪問(獲取)請求參數
1.方法
String 字符串變量 =request.getParameter("客戶端提供參數的name屬性名");
2.傳參數的三種形式
(1)使用JSP的forward和include動作
(2)在JSP頁面或HTML頁面中
(3)追加在網址後的參數傳遞或追加在超鏈接後面的參數
代碼練習: 3—8
<body>
<% String current param ="";
String current_vaul="";
request.setCharacterEncoding("UTF-8");
Enumeration params=request.getParameterNames();
while(params.hasMoreElements()){
current_param=(string)params.nextElement();
current_vaul=request.getParameter(current_param)
%>參數名稱:<%=current_param%>參數值;<%=current_vaul%><br>;
<%}%>
</body>
3.4.3 新屬性的設置與獲取
在頁面使用request對象的setAttribute("name",obj)方法,可以把數據obj設定request範圍(容器)內,請求轉發的頁面使用getAttribute(“name”)就可以
取得數據obj的值。
設置數據格式 : void request.getAttribute(String name);
獲得數據格式: object request.getAttribute(String name);
JSP復習(part 2 )