WebSphere Application Server - getServletContext not found

This is Interesting: Free IT Magazines  
Home > Archive > WebSphere Application Server > May 2004 > getServletContext not found





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author getServletContext not found
Eqbal Z

2004-05-26, 4:31 pm

I am using getServletContext to get some parameters set in web.xml but I
get an error like this.

javax.servlet.http.HttpSession: method getServletContext
()Ljavax/servlet/ServletContext; not found

I am using WAS 4.0.5

Any idea why this could be happenning. The application worked on Tomcat 5.
I have read somewhere that it could be a servlet version issue. If so what
is the alternative?
I basically need to get the values of some context parameters that I put in
web.xml for consuming a webservice.

Here is the code snippet:

public void valueBound (HttpSessionBindingEvent e)
{
// Retreive our context.
ServletContext context = e.getSession ().getServletContext () ;


setUserName (context.getInitParameter ("userName")) ;
setPassword (context.getInitParameter ("password")) ;
.....................
.......................
}


Thanks.
Ken Hygh

2004-05-26, 4:31 pm

Eqbal Z wrote:

>I am using getServletContext to get some parameters set in web.xml but I
>get an error like this.
>
>javax.servlet.http.HttpSession: method getServletContext
>()Ljavax/servlet/ServletContext; not found
>
>I am using WAS 4.0.5
>
>Any idea why this could be happenning. The application worked on Tomcat 5.
>I have read somewhere that it could be a servlet version issue. If so what
>is the alternative?
>I basically need to get the values of some context parameters that I put in
>web.xml for consuming a webservice.
>
>Here is the code snippet:
>
>public void valueBound (HttpSessionBindingEvent e)
> {
> // Retreive our context.
> ServletContext context = e.getSession ().getServletContext () ;
>
>
> setUserName (context.getInitParameter ("userName")) ;
> setPassword (context.getInitParameter ("password")) ;
> .....................
> .......................
> }
>
>
>Thanks.
>
>

Make sure you do not have any J2EE jars in your war/ear. This looks like
something in WAS is getting overridden.

OR

WAS 4.x is using Servlet 2.2, it's possible this API doesn't exist there.
Ken
Eqbal

2004-05-26, 4:31 pm

I definitely do not have j2ee.jar in my war. Is there an altenative way
I can get these parameter values from web.xml?
>Ken Hygh wrote:
> Eqbal Z wrote:
>
> Make sure you do not have any J2EE jars in your war/ear. This looks like
> something in WAS is getting overridden.
>
> OR
>
> WAS 4.x is using Servlet 2.2, it's possible this API doesn't exist there.
> Ken

Todd Kaplinger

2004-05-26, 4:31 pm

That is the problem.. session.getServletContext does not exist in
servlet 2.2. Do you absolutely need to do this from session? You
could get this via the ServletConfig object from within a servlet.

Eqbal wrote:
> I definitely do not have j2ee.jar in my war. Is there an altenative way
> I can get these parameter values from web.xml?
>
>


Eqbal

2004-05-26, 11:30 pm

I am trying to get the servlet context inside of a bean that is used on
a JSP page. I guess I might have to think of some other approach. Any
ideas, short of implementing JSP as a servlet?
Todd Kaplinger wrote:

> That is the problem.. session.getServletContext does not exist in
> servlet 2.2. Do you absolutely need to do this from session? You
> could get this via the ServletConfig object from within a servlet.
>
> Eqbal wrote:
>
>

Ken Hygh

2004-05-26, 11:30 pm

Eqbal wrote:
[vbcol=seagreen]
> I am trying to get the servlet context inside of a bean that is used
> on a JSP page. I guess I might have to think of some other approach.
> Any ideas, short of implementing JSP as a servlet?
> Todd Kaplinger wrote:
>
There should be a pre-defined 'context' variable that is the ServletContext.

Ken
Ray McVay

2004-05-26, 11:30 pm

Isn't that what the 'application' scope is in a JSP?

Ken Hygh wrote:
> There should be a pre-defined 'context' variable that is the
> ServletContext.
>
> Ken

Ken Hygh

2004-05-27, 4:34 pm

Ray McVay wrote:

> Isn't that what the 'application' scope is in a JSP?
>
> Ken Hygh wrote:
>
>

you're right, that's what I get for answering off the top of my head
without looking it up.
Ken
Eqbal

2004-05-27, 4:34 pm

How do I get the application object/context inside the bean? The bean
implements HttpSessionBindingListener and I would like to get some
parameter values defined in web.xml inside the valueBound method.

Ken Hygh wrote:
> Ray McVay wrote:
>
> you're right, that's what I get for answering off the top of my head
> without looking it up.
> Ken

Todd Kaplinger

2004-05-27, 4:34 pm

upgrade to an application server that implements the latest
specification. Or implement a controller servlet that takes the values
from the context and puts then in the session when the session is first
created.

Eqbal wrote:
> How do I get the application object/context inside the bean? The bean
> implements HttpSessionBindingListener and I would like to get some
> parameter values defined in web.xml inside the valueBound method.
>
> Ken Hygh wrote:
>
>


Ray McVay

2004-05-29, 11:35 pm

Good. I was afraid they had changed something in a newer JSP spec. 8-)
We're still stuck with 1.1 on our WAS 3.5 job.

Ken Hygh wrote:
> Ray McVay wrote:
>
> you're right, that's what I get for answering off the top of my head
> without looking it up.
> Ken

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com