Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
JSP - A mailing list about Java Server Pages specification and reference
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Oracle Connection Pooling in 3 2 2
Servlet : Session invalidate
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Tomcat and webapplication specific java library path
Running a Simple JMS Example
Mapping in workers2 properties
org apache jasper JasperException
Cannot find message resources under key org apache struts action
   MESSAGE
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
url string for connecting jboss to oracle
Value attribute of <html:checkbox
javax servlet ServletException: BeanUtils populate
HTTP Status 404 The requested resource is not available
5 0 18: Windows XP Pro vs Windows 2000
 
getting servletContext in actions

getting servletContext in actions

2007-01-31       - By Tom Schneider

 Back
Jeffrey,
You need to make sure your FactoryBean returns false for the isSingleton and
you might want to add lazy-load as well.  (I think singleton=false implies
lazy load, but I'm not sure)
Tom

On 1/31/07, Jeffrey Hau <jh398@(protected)> wrote:
>
> Hi Tom,
> I have tried your suggestion, my applicationContex.xml is now defined
> as,
>
> <bean id="scFactoryBean" class="StrutsServletContextLoader"/>
>      <bean id="servletCtx" factory-bean="scFactoryBean" factory-
> method="getServletContext"/>
>
>      <bean id="userService" class="user.RdfUserService">
>                 <constructor-arg index="0">
>                         <bean
> class="org.springframework.web.context.support.ServletContextResource Source code of org.springframework.web.context.support.ServletContextResource">
>                                 <constructor-arg index="0"
> ref="servletCtx"/>
>                                 <constructor-arg index="1" type="
> java.lang.String Source code of java.lang.String" value="/
> resources/users.rdf"/>
>                         </bean>
>                 </constructor-arg>
>      </bean>
>
>
> my StrutsServletContextLoader class consists of one method
>
> public ServletContext getServletContext() {
>                 return ServletActionContext.getServletContext();
>         }
>
> i am getting error from spring complaining missing servlet context.
>
> You mentioned ServletActionContext needs to the executed within the
> context of a webwork request, i think the problem is related to that.
> Do you know how can i make my StrutsServletcontextLoader be executed
> within a webwork request?
>
> many thanks
>
> Jeff
>
>
> On 31 Jan 2007, at 13:52, Tom Schneider wrote:
>
> > It would be very easy to create a Spring FactoryBean for this.
> > (Checkout the Spring Documentation if that doesn't make sense)
> > Then, to access the servlet context, just do a:
> >
> > ServletContext servletContext =
> > ServletActionContext.getServletContext();
> >
> > The FactoryBean would allow you to use dependency injection in
> > spring to inject the servlet context into any spring bean.  (I'm
> > doing a similar thing with some of the our legacy services and
> > components)  You could even convert the ServletContext into a Map
> > to decouple yourself from the servlet API.  That way your process
> > beans would only be dependent on a Map instead of a
> > ServletContext.  Keep in mind that the ServletActionContext is a
> > thread local, so it must be executed from within the context of a
> > webwork request.
> > Tom
> >
> >
> > Jeffrey Hau wrote:
> >> Hi Joe,
> >> Thanks for the helpful information. I am just wondering is it
> >> possible to get the ServletContext object in my spring
> >> applicationContext.xml? What i am trying to do now is to create a
> >> Resource object (ServletContextResource) and inject into a service
> >> class and then use this service class in a struts action. At the
> >> moment, I have to pass in the resource path (as a string) into the
> >> action, instantiate the ServletContextResource in the action then
> >> pass it to the service class.
> >>
> >> many thanks,
> >>
> >> Jeff
> >>
> >> On 31 Jan 2007, at 12:53, Joe Germuska wrote:
> >>
> >>> You need to make sure that your action is passing through an
> >>> interceptor-stack that includes ServletConfigInterceptor
> >>>
> >>> http://struts.apache.org/2.x/core/apidocs/org/apache/struts2/
> >>> interceptor/ServletConfigInterceptor.html
> >>>
> >>>
> >>> The struts-default package does include this.
> >>>
> >>> http://struts.apache.org/2.x/docs/struts-defaultxml.html
> >>>
> >>> Another thing you can do is call the static method
> >>> ServletActionContext.getServletContext() but this would be harder
> >>> to support
> >>> in a unit testing environment.  If  you implement
> >>> ServletContextAware, then
> >>> you could provide a mock ServletContext implementation in your
> >>> unit test
> >>> setup, while you'd have a lot more awkward setup to do to make
> >>> sure that
> >>> ServletActionContext.getServletContext was prepared to return a
> >>> usable
> >>> value.
> >>>
> >>> Joe
> >>>
> >>>
> >>> On 1/31/07, Nagraj Rao <nagraj.rao@(protected)> wrote:
> >>>>
> >>>> were u actually able to get the servletContext Object thru
> >>>> servletContextAware?? I'd tried it but couldn't get it :(
> >>>> do we need to do any additional stuff for that??
> >>>>
> >>>> -- -- Original Message -- --
> >>>> From: "Jeffrey Hau" <jh398@(protected)>
> >>>> To: "Struts Users Mailing List" <user@(protected)>
> >>>> Sent: Wednesday, January 31, 2007 4:55 PM
> >>>> Subject: [s2] getting servletContext in actions
> >>>>
> >>>>
> >>>> > Hi,
> >>>> > If i need to get a servletContext object in my action class, is
> >>>> > implementing the ServletContextAware interface the standard way
> >>>> of  doing
> >>>> > this? Is there any other alternatives?
> >>>> >
> >>>> > thanks,
> >>>> >
> >>>> > Jeff
> >>>> >
> >>>> >
> >>>> -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
> >>>> --
> >>>> > To unsubscribe, e-mail: user-unsubscribe@(protected)
> >>>> > For additional commands, e-mail: user-help@(protected)
> >>>> >
> >>>>
> >>>>
> >>>> -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
> >>>> --
> >>>> To unsubscribe, e-mail: user-unsubscribe@(protected)
> >>>> For additional commands, e-mail: user-help@(protected)
> >>>>
> >>>>
> >>>
> >>>
> >>> --Joe Germuska
> >>> Joe@(protected) * http://blog.germuska.com
> >>>
> >>> "The truth is that we learned from Jo?o forever to be out of tune."
> >>> -- Caetano Veloso
> >>
> >>
> >> -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
> >> To unsubscribe, e-mail: user-unsubscribe@(protected)
> >> For additional commands, e-mail: user-help@(protected)
> >>
> >>
> >
> >
> > -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
> > To unsubscribe, e-mail: user-unsubscribe@(protected)
> > For additional commands, e-mail: user-help@(protected)
> >
>
>
>

©2008 junlu.com - Jax Systems, LLC, U.S.A.