You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by rab yazbeck <ra...@yahoo.co.uk> on 2003/06/24 22:59:25 UTC

accessing servlet from an ActionForm

Hi.

I am trying to get access to the servlet container
(getServletContext().getAttribute(attrName)) from an
ActionForm but I receive an error
(NullPointerException). 

It is strange because the controller servlet instance
(ActionServlet) exist in the ActionForm, but every
time I try to access it, it gives me an error
(NullPointerException).

The ActionForm is crated by an <html-el:form>, and I
am trying to access this servlet from within the
constructor of this ActionForm (is it good practice to
do that?)

That attributes were already stored successfully
(plug-in) at the start-up of the application.

Help please, thank you in advance.

Rab.


__________________________________________________
Yahoo! Plus
For a better Internet experience
http://www.yahoo.co.uk/btoffer

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: accessing servlet from an ActionForm

Posted by rab yazbeck <ra...@yahoo.co.uk>.
Hum, i did try to oaste snippers and this is how I
knew that the problem is from the servlet
(ActionServlet).. every time i try to access it from
the constructor of the ActionForm it gives me a
NullPointerException.. 

I even tried only to do that:

servlet.getServletContext().getAttributeNames().   
toString()

And I still have this NullPointerException. Although i
tried to access it form an Action and it worked fine.

Any idea? 

 --- Varun Garg <va...@yahoo.com> wrote: > I am
not sure of the problem, but when an ActionForm
> is initialized the
> servlet is set automatically, so it should work from
> the Form also. 
> 
> Paste some more code snippets to explain whats
> happening, like the
> construtor and the jsp. Are you going directly to
> the jsp bypassing the
> action or your action is forwarding the request to
> jsp and even if you
> are it should work.
> 
>  
> 
> -----Original Message-----
> From: rab yazbeck [mailto:rablists@yahoo.co.uk] 
> Sent: Tuesday, June 24, 2003 4:11 PM
> To: Struts Users Mailing List
> Subject: RE: accessing servlet from an ActionForm
> 
> 
> But i am using it from within the ActionForm and not
> from the ActionServlet. And with the ActionForm, I
> am
> afraid that the "validate" and the "reset" are not
> called by the <html:form>, this is why i am using
> the constructor. any
> idea?
> 
>  --- Varun Garg <va...@yahoo.com> wrote: > I
> would access the ServletContext from the execute
> > or the perform method
> > rather than the constructor.
> > 
> >
> this.servlet.getServletContext().getAttribute("XXX")
> > 
> > This is what I use from inside the execute and it
> > works great.
> > 
> > 
> > -----Original Message-----
> > From: rab yazbeck [mailto:rablists@yahoo.co.uk]
> > Sent: Tuesday, June 24, 2003 3:59 PM
> > To: struts-user@jakarta.apache.org
> > Subject: accessing servlet from an ActionForm
> > 
> > 
> > Hi.
> > 
> > I am trying to get access to the servlet container
> > (getServletContext().getAttribute(attrName)) from
> an ActionForm but I 
> > receive an error (NullPointerException).
> > 
> > It is strange because the controller servlet
> > instance
> > (ActionServlet) exist in the ActionForm, but every
> > time I try to access it, it gives me an error
> (NullPointerException).
> > 
> > The ActionForm is crated by an <html-el:form>, and
> I
> > am trying to access this servlet from within the
> > constructor of this ActionForm (is it good
> practice
> > to
> > do that?)
> > 
> > That attributes were already stored successfully
> > (plug-in) at the start-up of the application.
> > 
> > Help please, thank you in advance.
> > 
> > Rab.
> > 
> > 
> > __________________________________________________
> > Yahoo! Plus
> > For a better Internet experience
> http://www.yahoo.co.uk/btoffer
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> > struts-user-help@jakarta.apache.org
> > 
> > 
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> > struts-user-help@jakarta.apache.org
> >  
> 
> __________________________________________________
> Yahoo! Plus
> For a better Internet experience
> http://www.yahoo.co.uk/btoffer
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
>  

__________________________________________________
Yahoo! Plus
For a better Internet experience
http://www.yahoo.co.uk/btoffer

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: accessing servlet from an ActionForm

Posted by Varun Garg <va...@yahoo.com>.
I am not sure of the problem, but when an ActionForm is initialized the
servlet is set automatically, so it should work from the Form also. 

Paste some more code snippets to explain whats happening, like the
construtor and the jsp. Are you going directly to the jsp bypassing the
action or your action is forwarding the request to jsp and even if you
are it should work.

 

-----Original Message-----
From: rab yazbeck [mailto:rablists@yahoo.co.uk] 
Sent: Tuesday, June 24, 2003 4:11 PM
To: Struts Users Mailing List
Subject: RE: accessing servlet from an ActionForm


But i am using it from within the ActionForm and not
from the ActionServlet. And with the ActionForm, I am
afraid that the "validate" and the "reset" are not
called by the <html:form>, this is why i am using the constructor. any
idea?

 --- Varun Garg <va...@yahoo.com> wrote: > I
would access the ServletContext from the execute
> or the perform method
> rather than the constructor.
> 
> this.servlet.getServletContext().getAttribute("XXX")
> 
> This is what I use from inside the execute and it
> works great.
> 
> 
> -----Original Message-----
> From: rab yazbeck [mailto:rablists@yahoo.co.uk]
> Sent: Tuesday, June 24, 2003 3:59 PM
> To: struts-user@jakarta.apache.org
> Subject: accessing servlet from an ActionForm
> 
> 
> Hi.
> 
> I am trying to get access to the servlet container
> (getServletContext().getAttribute(attrName)) from an ActionForm but I 
> receive an error (NullPointerException).
> 
> It is strange because the controller servlet
> instance
> (ActionServlet) exist in the ActionForm, but every
> time I try to access it, it gives me an error (NullPointerException).
> 
> The ActionForm is crated by an <html-el:form>, and I
> am trying to access this servlet from within the
> constructor of this ActionForm (is it good practice
> to
> do that?)
> 
> That attributes were already stored successfully
> (plug-in) at the start-up of the application.
> 
> Help please, thank you in advance.
> 
> Rab.
> 
> 
> __________________________________________________
> Yahoo! Plus
> For a better Internet experience http://www.yahoo.co.uk/btoffer
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
>  

__________________________________________________
Yahoo! Plus
For a better Internet experience
http://www.yahoo.co.uk/btoffer

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: accessing servlet from an ActionForm

Posted by rab yazbeck <ra...@yahoo.co.uk>.
But i am using it from within the ActionForm and not
from the ActionServlet. And with the ActionForm, I am
afraid that the "validate" and the "reset" are not
called by the <html:form>, this is why i am using the
constructor. any idea?

 --- Varun Garg <va...@yahoo.com> wrote: > I
would access the ServletContext from the execute
> or the perform method
> rather than the constructor.
> 
> this.servlet.getServletContext().getAttribute("XXX")
> 
> This is what I use from inside the execute and it
> works great.
> 
> 
> -----Original Message-----
> From: rab yazbeck [mailto:rablists@yahoo.co.uk] 
> Sent: Tuesday, June 24, 2003 3:59 PM
> To: struts-user@jakarta.apache.org
> Subject: accessing servlet from an ActionForm
> 
> 
> Hi.
> 
> I am trying to get access to the servlet container
> (getServletContext().getAttribute(attrName)) from an
> ActionForm but I receive an error
> (NullPointerException). 
> 
> It is strange because the controller servlet
> instance
> (ActionServlet) exist in the ActionForm, but every
> time I try to access it, it gives me an error
> (NullPointerException).
> 
> The ActionForm is crated by an <html-el:form>, and I
> am trying to access this servlet from within the
> constructor of this ActionForm (is it good practice
> to
> do that?)
> 
> That attributes were already stored successfully
> (plug-in) at the start-up of the application.
> 
> Help please, thank you in advance.
> 
> Rab.
> 
> 
> __________________________________________________
> Yahoo! Plus
> For a better Internet experience
> http://www.yahoo.co.uk/btoffer
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
>  

__________________________________________________
Yahoo! Plus
For a better Internet experience
http://www.yahoo.co.uk/btoffer

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: accessing servlet from an ActionForm

Posted by Varun Garg <va...@yahoo.com>.
I would access the ServletContext from the execute or the perform method
rather than the constructor.

this.servlet.getServletContext().getAttribute("XXX")

This is what I use from inside the execute and it works great.


-----Original Message-----
From: rab yazbeck [mailto:rablists@yahoo.co.uk] 
Sent: Tuesday, June 24, 2003 3:59 PM
To: struts-user@jakarta.apache.org
Subject: accessing servlet from an ActionForm


Hi.

I am trying to get access to the servlet container
(getServletContext().getAttribute(attrName)) from an
ActionForm but I receive an error
(NullPointerException). 

It is strange because the controller servlet instance
(ActionServlet) exist in the ActionForm, but every
time I try to access it, it gives me an error (NullPointerException).

The ActionForm is crated by an <html-el:form>, and I
am trying to access this servlet from within the
constructor of this ActionForm (is it good practice to
do that?)

That attributes were already stored successfully
(plug-in) at the start-up of the application.

Help please, thank you in advance.

Rab.


__________________________________________________
Yahoo! Plus
For a better Internet experience
http://www.yahoo.co.uk/btoffer

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org