By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 1,868 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

Problem JSP Bean data sharing with some Servlets

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.