Example usage for javax.servlet.jsp PageContext SESSION_SCOPE

List of usage examples for javax.servlet.jsp PageContext SESSION_SCOPE

Introduction

In this page you can find the example usage for javax.servlet.jsp PageContext SESSION_SCOPE.

Prototype

int SESSION_SCOPE

To view the source code for javax.servlet.jsp PageContext SESSION_SCOPE.

Click Source Link

Document

Session scope (only valid if this page participates in a session): the named reference remains available from the HttpSession (if any) associated with the Servlet until the HttpSession is invalidated.

Usage

From source file:org.apache.struts.taglib.bean.TestSizeTag.java

public void testSizeTagNamePropertyMapSessionScope() throws IOException, ServletException {
    request.setAttribute("runTest", "testSizeTagNamePropertyMapSessionScope");
    SimpleBeanForTesting sbft = new SimpleBeanForTesting();
    sbft.setMap(map);/*from  w w w .j  a v  a2 s  . c o  m*/
    pageContext.setAttribute(REQUEST_KEY, sbft, PageContext.SESSION_SCOPE);
    pageContext.forward("/test/org/apache/struts/taglib/bean/TestSizeTag.jsp");
}

From source file:org.apache.struts.taglib.bean.TestSizeTag.java

public void testSizeTagNamePropertyMapSessionScopeNested() throws IOException, ServletException {
    request.setAttribute("runTest", "testSizeTagNamePropertyMapSessionScopeNested");
    SimpleBeanForTesting sbft = new SimpleBeanForTesting();
    SimpleBeanForTesting sbft2 = new SimpleBeanForTesting();
    sbft.setMap(map);/*from  ww  w  .jav a  2  s  . c o  m*/
    sbft2.setNestedObject(sbft);
    pageContext.setAttribute(REQUEST_KEY, sbft2, PageContext.SESSION_SCOPE);
    pageContext.forward("/test/org/apache/struts/taglib/bean/TestSizeTag.jsp");
}

From source file:org.apache.struts.taglib.bean.TestWriteTag.java

private void runMyTest(String whichTest, String locale) {
    pageContext.setAttribute(Globals.LOCALE_KEY, new Locale(locale, locale), PageContext.SESSION_SCOPE);
    request.setAttribute("runTest", whichTest);
    try {/*from   w w w  .j a  v  a2s.  c om*/
        pageContext.forward("/test/org/apache/struts/taglib/bean/TestWriteTag.jsp");
    } catch (Exception e) {
        e.printStackTrace();
        fail("There is a problem that is preventing the tests to continue!");
    }
}

From source file:org.apache.struts.taglib.logic.TestIterateTag.java

public void testSessionScopeNameIterateList() throws ServletException, JspException, IOException {

    String testKey = "testSessionScopeNameIterateList";

    ArrayList lst = new ArrayList();
    for (int i = 0; i < iterations; i++) {
        lst.add("test" + i);
    }//  w  ww . j  av a 2  s .c o  m

    pageContext.setAttribute(testKey, lst, PageContext.SESSION_SCOPE);

    IterateTag tag = new IterateTag();
    tag.setPageContext(pageContext);
    tag.setId("theId");
    tag.setName(testKey);
    tag.setScope("session");

    int iteration = 0;
    tag.doStartTag();
    tag.doInitBody();
    do {
        out.print((String) pageContext.getAttribute("theId"));
        iteration++;

    } while (tag.doAfterBody() == tag.EVAL_BODY_TAG);
    tag.doEndTag();
    assertEquals(iterations, iteration);
}

From source file:org.apache.struts.taglib.logic.TestIterateTag.java

public void testSessionScopePropertyIteratesList() throws ServletException, JspException, IOException {

    String testKey = "testSessionScopePropertyIterate";

    ArrayList lst = new ArrayList();
    for (int i = 0; i < iterations; i++) {
        lst.add("test" + i);
    }//from   w  ww.ja  va 2 s.c o  m

    SimpleBeanForTesting sbft = new SimpleBeanForTesting();
    sbft.setList(lst);

    pageContext.setAttribute(testKey, sbft, PageContext.SESSION_SCOPE);

    IterateTag tag = new IterateTag();
    tag.setPageContext(pageContext);
    /*
     * Tests the equivalent of this tag in a jsp:
     *   <logic:iterate id="theId" name="testSessionScopePropertyIterate"
     *       scope="session">
     */
    tag.setId("theId");
    tag.setName(testKey);
    tag.setScope("session");
    tag.setProperty("list");

    int iteration = 0;
    tag.doStartTag();
    tag.doInitBody();
    do {
        out.print((String) pageContext.getAttribute("theId"));
        iteration++;

    } while (tag.doAfterBody() == tag.EVAL_BODY_TAG);
    tag.doEndTag();
    assertEquals(iterations, iteration);
}

From source file:org.apache.struts.taglib.logic.TestIterateTag.java

public void testSessionScopeNameIterateEnumeration() throws ServletException, JspException, IOException {

    String testKey = "testSessionScopeNameIterateEnumeration";

    StringTokenizer st = new StringTokenizer("Session Scope Name Iterate Enumeration");

    pageContext.setAttribute(testKey, st, PageContext.SESSION_SCOPE);

    IterateTag tag = new IterateTag();
    tag.setPageContext(pageContext);//from   ww w .ja  v a  2 s . com
    tag.setId("theId");
    tag.setName(testKey);
    tag.setScope("session");

    tag.doStartTag();
    tag.doInitBody();
    do {
        out.print((String) pageContext.getAttribute("theId"));

    } while (tag.doAfterBody() == tag.EVAL_BODY_TAG);
    tag.doEndTag();

}

From source file:org.apache.struts.taglib.logic.TestIterateTag.java

public void testSessionScopePropertyIterateEnumeration() throws ServletException, JspException, IOException {

    String testKey = "testSessionScopePropertyIterateEnumeration";

    StringTokenizer st = new StringTokenizer("Session Scope Property Iterate Enumeration");

    SimpleBeanForTesting sbft = new SimpleBeanForTesting();
    sbft.setEnumeration(st);//from  w ww.  j a v  a 2s  .  co m

    pageContext.setAttribute(testKey, sbft, PageContext.SESSION_SCOPE);

    IterateTag tag = new IterateTag();
    tag.setPageContext(pageContext);
    tag.setId("theId");
    tag.setName(testKey);
    tag.setScope("session");
    tag.setProperty("enumeration");

    tag.doStartTag();
    tag.doInitBody();
    do {
        out.print((String) pageContext.getAttribute("theId"));

    } while (tag.doAfterBody() == tag.EVAL_BODY_TAG);
    tag.doEndTag();

}

From source file:org.apache.struts.taglib.logic.TestIterateTag.java

public void testSessionScopeNameIterateMap() throws ServletException, JspException, IOException {

    String testKey = "testSessionScopeNameIterateMap";

    HashMap map = new HashMap();
    for (int i = 0; i < iterations; i++) {
        map.put("test" + i, "test" + i);
    }// ww  w  . j a  va  2s  . com

    pageContext.setAttribute(testKey, map, PageContext.SESSION_SCOPE);

    IterateTag tag = new IterateTag();
    tag.setPageContext(pageContext);
    tag.setId("theId");
    tag.setName(testKey);
    tag.setScope("session");

    int iteration = 0;
    tag.doStartTag();
    tag.doInitBody();
    do {
        out.print(pageContext.getAttribute("theId"));
        iteration++;

    } while (tag.doAfterBody() == tag.EVAL_BODY_TAG);
    tag.doEndTag();
    assertEquals(iterations, iteration);
}

From source file:org.apache.struts.taglib.logic.TestIterateTag.java

public void testSessionScopePropertyIterateMap() throws ServletException, JspException, IOException {

    String testKey = "testSessionScopePropertyIterateMap";

    HashMap map = new HashMap();
    for (int i = 0; i < iterations; i++) {
        map.put("test" + i, "test" + i);
    }/*from  w  w  w .  j av a2s. co  m*/

    SimpleBeanForTesting sbft = new SimpleBeanForTesting();
    sbft.setMap(map);

    pageContext.setAttribute(testKey, sbft, PageContext.SESSION_SCOPE);

    IterateTag tag = new IterateTag();
    tag.setPageContext(pageContext);
    tag.setId("theId");
    tag.setName(testKey);
    tag.setScope("session");
    tag.setProperty("map");

    int iteration = 0;
    tag.doStartTag();
    tag.doInitBody();
    do {
        out.print(pageContext.getAttribute("theId"));
        iteration++;

    } while (tag.doAfterBody() == tag.EVAL_BODY_TAG);
    tag.doEndTag();
    assertEquals(iterations, iteration);
}

From source file:org.apache.struts.taglib.logic.TestIterateTag.java

public void testSessionScopeNameIterateArray() throws ServletException, JspException, IOException {

    String testKey = "testSessionScopeNameIterateArray";

    String[] tst = new String[iterations];
    for (int i = 0; i < tst.length; i++) {
        tst[i] = "test" + i;
    }/*from  w ww . j a v  a2s . c  o m*/

    pageContext.setAttribute(testKey, tst, PageContext.SESSION_SCOPE);

    IterateTag tag = new IterateTag();
    tag.setPageContext(pageContext);
    tag.setId("theId");
    tag.setName(testKey);
    tag.setScope("session");

    int iteration = 0;
    tag.doStartTag();
    tag.doInitBody();
    do {
        out.print(pageContext.getAttribute("theId"));
        iteration++;

    } while (tag.doAfterBody() == tag.EVAL_BODY_TAG);
    tag.doEndTag();
    assertEquals(iterations, iteration);
}