You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Rui Oliveira <ol...@milu.ipn.pt> on 2000/08/23 00:00:47 UTC

How can I have two beans in the same JSP?

Hello,

I have 2 JSPS and I want to get a variable from one to the other. 

Lets say that I have a page called "page1.jsp" and that I have a
"bean_A" in this page. One of the methods from that bean returns a value
that I must use in the next JSP, lets call it "page2.jsp". 

My question is: do I need to open the first bean (bean_A) in the second
page (page2.jsp), in order to get the value from that bean? If so, how
can I keep the state of that bean, so that it wont lose its value from
page1.jsp to page2.jsp?


Thx

Rui

RE: How can I have two beans in the same JSP?

Posted by Phuc Truong <pt...@experience.com>.
Two ways I can think of, the first way is better if you have a non-java.lang
object that can't be parsed back from a string:

1. add the value to the session on page 1:
	session.put("value", foo)

on then page2 get the value:
	foo = (FooClass) session.get("value");
	session.remove("value");

2. passing the value as a cgi parameter:
	response.sendRedirect("page2.jsp?value=foo");

on page 2:
	String foo = request.getParameter("value");
	Integer foo = new Integer(request.getParameter("value"));

-Phuc

-----Original Message-----
From: Rui Oliveira [mailto:oliveira@milu.ipn.pt]
Sent: Tuesday, August 22, 2000 6:01 PM
To: tomcat-user@jakarta.apache.org
Subject: How can I have two beans in the same JSP?


Hello,

I have 2 JSPS and I want to get a variable from one to the other.

Lets say that I have a page called "page1.jsp" and that I have a
"bean_A" in this page. One of the methods from that bean returns a value
that I must use in the next JSP, lets call it "page2.jsp".

My question is: do I need to open the first bean (bean_A) in the second
page (page2.jsp), in order to get the value from that bean? If so, how
can I keep the state of that bean, so that it wont lose its value from
page1.jsp to page2.jsp?


Thx

Rui


RE: How can I have two beans in the same JSP?

Posted by George McKInney <ge...@tantalus.com>.
>
> I have 2 JSPS and I want to get a variable from one to the other.
>
You can simply put a useBean tag in each of the pages, using the same id
(and class).
If the .jsps will be handling the same request (using forward, for instance)
you can specify that the bean have request scope.

If they will be used within the same session, but not necessarily the same
request, use session scope. In this case make sure that you haven't used <%@
page session = "false" ... %>, which (I think) will prevent the page's using
a bean with session scope.

George McKinney, Developer
tantalus communications inc.
500-1122 Mainland Street
Vancouver, BC, Canada V6B 5L1
george@tantalus.com

Direct  604.726.6753
Main    604.609.0700
Fax     604.609.0705
www.tantalus.com
"When eBusiness experience counts."