• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Bean Scope??

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am using A.jsp, B.jsp and i want to use the bean created in A.jsp in B.jsp.But, in B.jsp its giving always as null.
A.jsp
<%@ page class="classname" %>
<jsp:useBean id="mybean" scope="session" class="classname" />
<jsp:setProperty name="mybean" property="property1" param="param1" />
B.jsp
<%@ page class="classname" %>
<jsp:useBean id="mybean" scope="session" class="classname" />
<jsp:getProperty name="mybean" proprety="property1" />
Please , suggest me any options to make "mybean" working in B.jsp.
Thanks
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Naresh,
We can make A.jsp to set a session var and abother b.jsp grab the var's value set by previous a.jsp. Here is the sample code I tested. Don't bother about the package of the bean. I just used a sample file which used for another Javaranch user's question.
If you want a plain bean, just remove the package statements in .java file and from all .jsps and place bean's .class file directly under ../appnName/web-inf/classes directory.


Is this what you wanted ?
regds
maha anna
[This message has been edited by maha anna (edited March 20, 2001).]
 
Naresh Babu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! Maha for the reply.I am using the code which
you have given.But , output is "null" for
<%=worksheet_bean.getPassword()%> (in test2.jsp).
In test1.jsp, i am able to retreive the value.
My problem, is the "worksheet_bean" (created in test1.jsp)
cannot be accessed in test2.jsp.
Thanks

 
Naresh Babu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! Maha for the reply.I am using the code which
you have given.But , output is "null" for
<%=worksheet_bean.getPassword()%> (in test2.jsp).
In test1.jsp, i am able to retreive the value.
My problem, is the "worksheet_bean" (created in test1.jsp)
cannot be accessed in test2.jsp.
Thanks


[This message has been edited by Naresh Babu (edited March 20, 2001).]
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using Tomcat? I tested with both scope='session' and scope='application' and got the results in test2.jsp both times.
By default all pages (.jsps) participate in session, which means
<%@page session="true" %> <% -- Default -- %>
Anyhow try to put this line as first code in test1.jsp and test2.jsp and let us know.
regds
maha anna
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the above change doesn't work try this method. If this way works, you should get "Maha Soorya Anna Naresh" when you first call test1.jsp and latter call test2.jsp.

 
Naresh Babu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Allaire . I tried including session="true" in both
the files.
If i use the setAttribute , i am able to retreive the value.But i want to
user setProperty and getProperty methods.
Thanks!

[This message has been edited by Naresh Babu (edited March 20, 2001).]
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the servlet engine is written according to servlet 2.2 spec it should work the way we expect. I suspect the implementation.
What's your goal? a.jsp should freshly create a bean when called eachtime /first time and other jsps should be able to read the session bean's values ?
Please give some more info of your need so that we can find a work-around.
regds
maha anna
 
Naresh Babu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, i was not able to reply immediately. The Allaire server which i am working on , has support for servlet 2.2.

My goal:In our project we have different pages
where the user enters data.At the end of all
jsp pages the data entered by user in previous
jsp pages has to be written to a text file.
If we are going for attributes , for a single
client there would be 70-80 attributes in a session.
It will be difficult to retreive the attributes.

So, i thought if we use bean and store the data
in bean,then we can insert all the data whenever required.
Please , suggest me if there is a better option.
Thanks! for your response.

Thanks
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Naresh,
Since those setProperty and getProperty's don't work properly in Allaire, here is a work-around which comes to mind.
Let the bean's constructor take HTTPRequest as argument and init itself like this.


I haven't tested this code. There could be some syntax errors. But you get the logic!
regds
maha anna
 
Naresh Babu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! for the reply.I got it now , when i use
value="XXX" in setProperty.Previoulsy ,
i user param="param1" where param1 is a text field.
So, i think i will retreive the value from textfield
and the use value="XXX" instead of param="param1".

I am v.sorry , for the trouble.I will try the code
which u have given.
Thanks.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic