النتائج 1 إلى 2 من 2

الموضوع: How to use Session Scope in JSP

  1. #1
    elfr3on el3ashk الصورة الرمزية A7med Baraka
    تاريخ التسجيل
    Jun 2008
    الدولة
    Egypt - Cairo
    المشاركات
    4,695
    معدل تقييم المستوى
    10

    افتراضي How to use Session Scope in JSP


    End Google Ads 201810 - BS.net 01 -->
    A session is an object associated with a visitor. Data can be put in the session and retrieved from it, much like a Hash table. A different set of data is kept for each visitor to the site.
    Here is a set of pages that put a user's name in the session, and display it elsewhere. Try out installing and using these.
    First write a form, let us call it DemoSession.html
    DemoSession.html
    كود:
    <HTML>
    <BODY>
    <FORM METHOD=POST ACTION="DemoSession.jsp">
    What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20>
    <P><INPUT TYPE=SUBMIT>
    </FORM>
    </BODY>
    </HTML>

    The target of the form is "DemoSession.jsp", which saves the user's name in the session.
    DemoSession.jsp
    كود:
    <% String name = request.getParameter( "username" ); session.setAttribute( "theName", name ); %> <HTML> <BODY> <A HREF="NextPage.jsp">Continue</A> </BODY> </HTML>



    The DemoSession.jsp saves the user's name in the session, and puts a link to another page, NextPage.jsp.
    NextPage.jsp shows how to retrieve the saved name.
    NextPage.jsp
    كود:
    <HTML> <BODY> Hello, <%= session.getAttribute( "theName" ) %> </BODY> </HTML>



    The session is kept around until a timeout period. Then it is assumed that the user is no longer visiting the site, and the session is discarded.


  • #2
    elfr3on el3ashk الصورة الرمزية A7med Baraka
    تاريخ التسجيل
    Jun 2008
    الدولة
    Egypt - Cairo
    المشاركات
    4,695
    معدل تقييم المستوى
    10

    افتراضي رد: How to use Session Scope in JSP + Example

    كود:
    <%@ page errorPage="errorpage.jsp" %>
    
    <html>
    <head>
    <title>UseSession</title>
    </head>
    <body>
    <%
    Integer count = (Integer)session.getAttribute("COUNT");
    // If COUNT is not found, create it and add it to the session
    if ( count == null ) {
    
    count = new Integer(1);
    session.setAttribute("COUNT", count);
    }
    else {
    count = new Integer(count.intValue() + 1);
    session.setAttribute("COUNT", count);
    }  
    out.println("<b>Hello you have visited this site: "
    + count + " times.</b>");
    %>
    </body>
    </html>

  • معلومات الموضوع

    الأعضاء الذين يشاهدون هذا الموضوع

    الذين يشاهدون الموضوع الآن: 1 (0 من الأعضاء و 1 زائر)

    المواضيع المتشابهه

    1. Management Scope in connection options
      بواسطة C# Programming في المنتدى General topics in C# - CSharp
      مشاركات: 0
      آخر مشاركة: 01-22-2010, 11:11 AM
    2. Function out of scope
      بواسطة C++ Programming في المنتدى General topics in C++ - Cplusplus
      مشاركات: 0
      آخر مشاركة: 09-08-2009, 03:13 PM
    3. How to increase the scope in an if statement [modified]
      بواسطة C# Programming في المنتدى General topics in C# - CSharp
      مشاركات: 0
      آخر مشاركة: 07-12-2009, 03:31 AM
    4. How to increase the scope of something in an if statement
      بواسطة C# Programming في المنتدى General topics in C# - CSharp
      مشاركات: 0
      آخر مشاركة: 07-12-2009, 02:51 AM
    5. using versus out of scope
      بواسطة C# Programming في المنتدى General topics in C# - CSharp
      مشاركات: 0
      آخر مشاركة: 06-25-2009, 10:10 PM

    الكلمات الدلالية لهذا الموضوع

    مواقع النشر (المفضلة)

    ضوابط المشاركة

    • لا تستطيع إضافة مواضيع جديدة
    • لا تستطيع الرد على المواضيع
    • لا تستطيع إرفاق ملفات
    • لا تستطيع تعديل مشاركاتك
    •  
    "وَقُل رَّبِّ زِدْنِي عِلْمًا"
    أعلانات نصية أستضافة , ريسيلر - Best Hosting | BarakaSoft Web Solutions

    BarakaSoft PageRank RSS RSS 2.0 XML MAP HTML 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 C/C++ | Java | C# | Network | Database | OS | Linux | Windows | Hacker & Security | Photoshop | Flash | Web Development | Free Programs | Mobile App | Free Java Course | Latest Technical News | Internet Programs | Antiviurse Programs | Graphics Programs | Network Programs | Portable Programs | vb Forums Development | Forums Development | CMS(Joomla-nuke-wordpress-mkportal...) | Photo | Anime |