JSP: usebean access the arraylist generated in the first JSP page on the second JSP page

Source: Internet
Author: User

I wowould like to do the following but I cannot access the arraylist
The JSP. cocould anyone help?

1. Use the doview ()-method to store an arraylist IN THE SESSION
========================================================== ======================================
Doview (){
....
Mysimplebean my1 = new mysimplebean ();
My1.setmessage ("test1 ");
Mysimplebean my2 = new mysimplebean ();
My2.setmessage ("Test2 ");
Arraylist mysimplebeans = new arraylist ();
Mysimplebeans. Add (my1 );
Mysimplebeans. Add (my2 );
Request. getportletsession (). setattribute ("Jens", mysimplebeans,
Portletsession. portlet_scope );
....
}

2. Access this bean from the JSP (this does not work)
========================================================== ======================================
<% @ Page session = "true" contenttype = "text/html"
Import ="Java . Util. *, javax. Portlet .*,
Com. Linde. Portal . Application. Domino. Pike. navigatio N. * "%>
<% @ Taglib uri = "http://java.sun.com/portlet" prefix = "Portlet" %>
<% @ Taglib uri = "http://java.sun.com/jstl/core" prefix = "C" %>
<% @ Taglib uri = "http://java.sun.com/jstl/fmt" prefix = "FMT" %>
<Portlet: defineobjects/>

<JSP: usebean id = "Jens"
Class = "com. Linde. Portal. application. Domino. Pike. Na vigation. mysimplebean"
Scope = "session"> </jsp: usebean>

<Table>
<C: foreach Var = "mysimplebean" items = "$ {Jens}">
<Tr>
<TD> <cut value = "$ {mysimplebean. Message}"/> </TD>
</Tr>
</C: foreach>
</Table>

3. This code works...
========================================================== ======================================
....
<%
Arraylist jens2 = NULL;
Try {
Portletsession mysession = renderrequest. getportletsession ();
Jens2 = (arraylist) mysession. getattribute ("Jens ",
Portletsession. portlet_scope );}
Catch (exception e ){
E. printstacktrace (system. Out );
} %>
<%
If (jens2! = NULL ){
%>
<% = (Mysimplebean) jens2.get (0). getmessage () %>
<%} Else {%>
<% = "Empty" %>
<% }%>

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

Posts: N/

Re: JSP: usebean-access arraylist containing beans?

I looked at it once more and noticed the following which seems to be
Related to the problem. I can access the attribute "jens2" in the JSP
But I cannot access the attribute "jens3". There will be an empty
String cerated for "jens3". Can you explain me why?

Thanks!

Portlet
========================================================== ======================================
Doview (){...
Request. setattribute ("jens2", "request Hello World ");
Request. getportletsession (). setattribute ("jens3", "session hello
World ");
....}

JSP
========================================================== ======================================
<JSP: usebean id = "jens2" class = "Java. Lang. String"
Scope = "request"> </jsp: usebean>
<JSP: usebean id = "jens3" class = "Java. Lang. String"
Scope = "session"> </jsp: usebean>
....

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.