jsp jsp:useBean 在第二個jsp頁面訪問第一個jsp頁面中產生的ArrayList

來源:互聯網
上載者:User

i would like to do the following but i cannot access the ArrayList via
the JSP. could 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/a

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>
....

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.