<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-59  評論-31  文章-0  trackbacks-0

    request.getParameter
    是用來接受來自get方法或post方法的參數
    <form method=post>
    <form method=get>
    <a href="1.jsp?id=1">ok</a>
    只能接受java.lang.String
    也就是說String hotel_id = request.getParameter("hotel_id");
    request.getAttribute
    是用來接受來自servlet的變量或Action(其實Action就是特殊的Servlet)
    在Action中,request.setAttribute("ret",ret);
    只能接受java.lang.Object
    也就是說List ret = (List)request.getAttribute("ret");

    一個是變量類型,一個對象類型

    http協議中

    get形式的請求的參數是在
    url的 ? 后面
    如 http://xxx.xxx.xxx/aaa.jsp?a=1

    post形式的請求的參數是在請求的體里,沒有在http的頭部

    -------------------------------------------
    以下是get形式的請求 http協議部分

    GET /aaa.jsp?a=1 HTTP/1.1
    Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*
    Accept-Language: zh-cn
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Embedded Web Browser from: http://bsalsa.com/; .NET CLR 1.1.4322)
    Host: 127.0.0.1:8080
    Connection: Keep-Alive

    以下是post形式的請求 http協議部分
    POST /aaa.jsp HTTP/1.1
    Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*
    Referer: http://127.0.0.1:8080/b.html
    Accept-Language: zh-cn
    Content-Type: application/x-www-form-urlencoded
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Embedded Web Browser from: http://bsalsa.com/; .NET CLR 1.1.4322)
    Host: 127.0.0.1:8080
    Content-Length: 48
    Connection: Keep-Alive
    Cache-Control: no-cache
    Cookie: JSESSIONID=111

    a=1

    -------------------------------------
    看到區別的吧
    也有共同點,這些參數的值都是保存在http請求部分
    以上這種參數都需要通過request.getParameter()方法取得參數的值

    =======================================================


    request.getAttribute()方法所取得的值是保存在服務器端的
    服務器端的4個內置對象
    page
    request
    session
    application
    中保存的數據都需要通過 getAttribute()方法取得

    引自:http://www.javathinker.org/bbs/topic.jsp?db=2&topic=76

    HttpServletRequest類既有getAttribute()方法,也由getParameter()方法,這兩個方法有以下區別:

    (1)HttpServletRequest類有setAttribute()方法,而沒有setParameter()方法

    (2)當兩個Web組件之間為鏈接關系時,被鏈接的組件通過getParameter()方法來獲得請求參數,例如假定welcome.jsp和authenticate.jsp之間為鏈接關系,welcome.jsp中有以下代碼:

    <a href="authenticate.jsp?username=weiqin">authenticate.jsp </a>

    或者:

    <form name="form1" method="post" action="authenticate.jsp">
       請輸入用戶姓名:<input type="text" name="username">
       <input type="submit" name="Submit" value="提交">
    </form>

    在authenticate.jsp中通過request.getParameter("username")方法來獲得請求參數username:

    <% String username=request.getParameter("username"); %>

    (3)當兩個Web組件之間為轉發關系時,轉發目標組件通過getAttribute()方法來和轉發源組件共享request范圍內的數據。假定authenticate.jsp和hello.jsp之間為轉發關系。authenticate.jsp希望向hello.jsp傳遞當前的用戶名字,如何傳遞這一數據呢?先在authenticate.jsp中調用setAttribute()方法:

    <%
    String username=request.getParameter("username");
    request.setAttribute("username",username);
    %>

    <jsp:forward page="hello.jsp" />

    在hello.jsp中通過getAttribute()方法獲得用戶名字:

    <% String username=(String)request.getAttribute("username"); %>
    Hello: <%=username %>

    從更深的層次考慮,request.getParameter()方法傳遞的數據,會從Web客戶端傳到Web服務器端,代表HTTP請求數據。request.getParameter()方法返回String類型的數據。

    request.setAttribute()和getAttribute()方法傳遞的數據只會存在于Web容器內部,在具有轉發關系的Web組件之間共享。這兩個方法能夠設置Object類型的共享數據。

     

    本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/wirror800/archive/2009/04/04/4048764.aspx

    posted on 2009-06-25 22:01 RoyPayne 閱讀(1172) 評論(0)  編輯  收藏 所屬分類: jsp相關
    主站蜘蛛池模板: 亚洲va乱码一区二区三区| 国产精品国产亚洲精品看不卡| 久久久亚洲AV波多野结衣| 在线观看片免费人成视频播放| 免费一级成人毛片| 高h视频在线免费观看| 国产jizzjizz视频全部免费| 亚洲av最新在线观看网址| 男人的好看免费观看在线视频| 亚洲精品456人成在线| 日韩精品无码区免费专区| 中文字幕精品三区无码亚洲| 最近2019中文字幕免费看最新| 亚洲а∨天堂久久精品9966| 女人18毛片特级一级免费视频 | 亚洲伊人久久大香线蕉苏妲己| 丁香花在线视频观看免费| 亚洲国产精品线在线观看| 91人成网站色www免费下载| 亚洲国产成人精品电影| 成人免费看黄20分钟| 国产99久久亚洲综合精品| 国产亚洲精品线观看动态图| 两个人看的www免费| 亚洲精品美女在线观看| 看全色黄大色大片免费久久| 男性gay黄免费网站| 亚洲精品无码高潮喷水在线| 免费女人高潮流视频在线观看| 亚洲乱码一区av春药高潮| 日本特黄特色免费大片| 伊人久久大香线蕉免费视频| 亚洲色欲www综合网| 免费鲁丝片一级在线观看| 成年免费大片黄在线观看com| 国产精品亚洲а∨无码播放| 国产va精品免费观看| 一级做性色a爰片久久毛片免费| 亚洲精品国偷自产在线| 97在线观免费视频观看 | 丁香五月亚洲综合深深爱|