getServletContext() cannot be resolved...

694 views
Skip to first unread message

Ziggi

unread,
Apr 28, 2011, 4:40:47 PM4/28/11
to red5in...@googlegroups.com
Ok,

It's all not that easy... I try to use "getServletContext()" method in my Red5 servlet but I constantly get error:

The method getServletContext() is undefined

I tried to add import from import javax.servlet.Servlet (I found this class in tomcat-6.0.14-servlet-api.jar but that not helped.

Can you please show me exactly how to use getServletContext() method in a custom servlet class?

Thanks ahead !

Ziggi

unread,
Apr 28, 2011, 5:15:57 PM4/28/11
to red5in...@googlegroups.com
Actually I am going to read context parameters like this:

String foo = getServletContext().getInitParameter("foo");

Can you help, please?

Rajdeep Rath

unread,
Apr 28, 2011, 7:04:18 PM4/28/11
to red5in...@googlegroups.com
Dont do like that. Create a bean with property on it that you want to be the variable. then create getter and setter functions in side that bean for that variable.

Ziggi

unread,
Apr 29, 2011, 3:01:16 AM4/29/11
to red5in...@googlegroups.com
Hi Rajdeep,

Nope - I am not going to read/write an object property here.
I am going to read data from web.xml like this:

web.xml:
<context-param>
   
<param-name>foo</param-name>
   
<param-value>bar</param-value>
</context-param>

servlet class:

String foo = getServletContext().getInitParameter("foo"); // will be "bar"

Can you help me please?

Mondain

unread,
Apr 29, 2011, 9:34:46 AM4/29/11
to red5in...@googlegroups.com

Ziggi

unread,
Apr 29, 2011, 12:58:54 PM4/29/11
to red5in...@googlegroups.com
Thank you !!!

Ziggi

unread,
Apr 29, 2011, 2:37:38 PM4/29/11
to red5in...@googlegroups.com
I have a problem with your example. What I am trying to do is to read context parameter in remoting not regular HTTP Get/Post requests.

Then I tried:

public class RemoteMethods extends HttpServlet implements IServiceHandlerProvider {

      public void init(ServletConfig config) throws ServletException  {
            super.init(config);
            ServletContext context = getServletContext();
      }

But it seems in this case servlet init method is never invoked...

On the other hand getServletContext() brings invocation failure when used within a pubic method:

java.lang.reflect.InvocationTargetException: null

Any idea how to use that properly?

Ziggi

unread,
Apr 29, 2011, 2:44:27 PM4/29/11
to red5in...@googlegroups.com
Simply speaking - how to getServletContext() inside a remoting service handler ???
Reply all
Reply to author
Forward
0 new messages