470,862 Members | 1,816 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,862 developers. It's quick & easy.

Problem JSP Bean data sharing with some Servlets

Hi all,
I want to share some data for all my applications (servlets and jsps).
For this i am using a JSP to set the variables with scope=application.
When i get this data from some JSP all is o.k, i can see the data that
i saved, but when i get access with my servlets, i can't see data
saved prev.
My request is simple: save data with a JSP and read this data with
servlets.? please if you send me a small sample to do this. or tell me
where is my mistake:
In the JSP (A):
<jsp:useBean id="facturacionLogonBean" class="FacturacionLogonBean"
scope="application" />
In the Servlet (B):
FacturacionLogonBean myfacturacionLogonBean = new
FacturacionLogonBean();
String aafsistema = myfacturacionLogonBean.getFsistema();
the statement System.out.println("+++my data" + aafsistema); don't
display my data
Thanks
JMUNOZ
Jul 17 '05 #1
3 6362
Jose Munoz wrote:
Hi all,
I want to share some data for all my applications (servlets and jsps).
For this i am using a JSP to set the variables with scope=application.
When i get this data from some JSP all is o.k, i can see the data that
i saved, but when i get access with my servlets, i can't see data
saved prev.
My request is simple: save data with a JSP and read this data with
servlets.? please if you send me a small sample to do this. or tell me
where is my mistake:
In the JSP (A):
<jsp:useBean id="facturacionLogonBean" class="FacturacionLogonBean"
scope="application" />
In the Servlet (B):
FacturacionLogonBean myfacturacionLogonBean = new
FacturacionLogonBean();
String aafsistema = myfacturacionLogonBean.getFsistema();
the statement System.out.println("+++my data" + aafsistema); don't
display my data
Thanks
JMUNOZ

As I do not fully understand what you are trying to achieve, let me give you
this:
- I assume that you are creating 2 instances of your bean class?
So how does this bean look like? Is it a static (or class variable)
variable that you return with getFsistema()?
- I would recommend to use the context attributes to share date among all
servlets (remember JSP's are servlets ) that persist for the lifetime of
the application.
Brgds,
Herman
--
Suse Linux Professional 8.1 on Athlon 1.1 Ghz 512 Mb
Anti Spam = remove the "dot" and the "at"
Registered Linux User #264690
Jul 17 '05 #2
jm******@hotmail.com (Jose Munoz) wrote in message news:<6a**************************@posting.google. com>...
Hi all,
I want to share some data for all my applications (servlets and jsps).
For this i am using a JSP to set the variables with scope=application.
When i get this data from some JSP all is o.k, i can see the data that
i saved, but when i get access with my servlets, i can't see data
saved prev.
My request is simple: save data with a JSP and read this data with
servlets.? please if you send me a small sample to do this. or tell me
where is my mistake:
In the JSP (A):
<jsp:useBean id="facturacionLogonBean" class="FacturacionLogonBean"
scope="application" />
In the Servlet (B):
FacturacionLogonBean myfacturacionLogonBean = new
FacturacionLogonBean();
String aafsistema = myfacturacionLogonBean.getFsistema();
the statement System.out.println("+++my data" + aafsistema); don't
display my data
Thanks
JMUNOZ

facturacionLogonBean and myfacturacionLogonBean are two different
FacturacionLogonBean objects. So this is not the issue of sharing one
object by two parties, JSP and servlet. Best solution might be, as
Herman has suggested, use ServletContext raum by, for example,
implementing ServletContextListener.
Jul 17 '05 #3
You need to use the ServletContext to get access to your bean at the
application scope level. Do like this in your servlet:
-----------------------------------
ServletContext context = getServlet().getServletContext();
FacturacionLogonBean myfacturacionLogonBean = new FacturacionLogonBean();
myfacturacionLogonBean =context.getAttribute("facturacionLogonBean");
-----------------------------
Larry

"Jose Munoz" <jm******@hotmail.com> wrote in message
news:6a**************************@posting.google.c om...
Hi all,
I want to share some data for all my applications (servlets and jsps).
For this i am using a JSP to set the variables with scope=application.
When i get this data from some JSP all is o.k, i can see the data that
i saved, but when i get access with my servlets, i can't see data
saved prev.
My request is simple: save data with a JSP and read this data with
servlets.? please if you send me a small sample to do this. or tell me
where is my mistake:
In the JSP (A):
<jsp:useBean id="facturacionLogonBean" class="FacturacionLogonBean"
scope="application" />
In the Servlet (B):
FacturacionLogonBean myfacturacionLogonBean = new
FacturacionLogonBean();
String aafsistema = myfacturacionLogonBean.getFsistema();
the statement System.out.println("+++my data" + aafsistema); don't
display my data
Thanks
JMUNOZ

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Jeff | last post: by
1 post views Thread by bhadram | last post: by
61 posts views Thread by Steven T. Hatton | last post: by
1 post views Thread by elsheh | last post: by
2 posts views Thread by nvidia1 | last post: by
reply views Thread by radhi | last post: by
2 posts views Thread by judge82 | last post: by
1 post views Thread by ITCraze | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.