users@jersey.java.net

Re: [Jersey] ServeltContext is always null

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 31 Jul 2009 10:25:43 +0200

On Jul 30, 2009, at 8:08 PM, George Hallak wrote:

> I'm using the version that comes with Netbeans 6.5, which is 1.0.
> It's configured to be deployed as a servlet, and I'm deploying it on
> Tomcat.
>

I just tried a simple resource class and it worked fine for me (i used
NB 6.7 but it uses the same Jersey version, 1.0):

@Path("generic")
public class GenericResource {
     @Context
     private ServletContext sc;

     @GET
     public String getXml() {
         return sc.toString();
     }
}

and it generated the following web.xml:

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd
">
     <servlet>
         <servlet-name>ServletAdaptor</servlet-name>
         <servlet-
class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-
class>
         <load-on-startup>1</load-on-startup>
     </servlet>
     <servlet-mapping>
         <servlet-name>ServletAdaptor</servlet-name>
         <url-pattern>/resources/*</url-pattern>
     </servlet-mapping>
     <session-config>
         <session-timeout>
             30
         </session-timeout>
     </session-config>
     <welcome-file-list>
         <welcome-file>index.jsp</welcome-file>
     </welcome-file-list>
</web-app>

Paul.


> On Thu, Jul 30, 2009 at 1:28 AM, Paul Sandoz <Paul.Sandoz_at_sun.com>
> wrote:
> Hi George,
>
> A couple of questions:
>
> - what version of Jersey are you using?
>
> - have you configured Jersey to be deployed as a Servlet or a Filter?
>
> - are you deploying using a Web container, such as GlassFish or
> Tomcat, or an embedded server such as Grizzly ?
>
> Paul.
>
>
> On Jul 29, 2009, at 10:35 PM, George Hallak wrote:
>
> Hi,
>
> I'm trying to inject ServletContext, but it's always null. The code
> I'm using is:
>
> @Context ServletContext context;
>
> I'm able to inject HttpServletRequest, but ServletContext is always
> null.
> Any suggestion?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>