aspose file tools*
The moose likes Spring and the fly likes Getting request object outside of DispatchServlet. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Getting request object outside of DispatchServlet." Watch "Getting request object outside of DispatchServlet." New topic
Author

Getting request object outside of DispatchServlet.

Jay Abrahm
Ranch Hand

Joined: May 28, 2008
Posts: 183
I am trying to get the request object so that I could get the application URL outside of the dispatch servlet. I tried all three methods below and it returned null.

Is there any other way to get the request object from the RequestContextListener



My web.xml has the following code.



Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

Where are you putting this code? In a Spring MVC Controller, a Servlet, a Struts Action. We need a little more context.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Jay Abrahm
Ranch Hand

Joined: May 28, 2008
Posts: 183
I should have attached this earlier.

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

Next question, how is that code being called. If is comes from a request already and goes first into the Controller or Action, then just get the data out of the request there and pass that down.

I think there is a design/architecture design flaw where you would need the HttpServletRequest passing into a non-controller/action class.

Mark
Jay Abrahm
Ranch Hand

Joined: May 28, 2008
Posts: 183
The Spring container (if I can use that work here) calls this class since I have AbstractRoutingDataSource defined.

I basically need the HttpServletRequest so that I can get the URL to decide the datasource to connect to. If I can get the URL parameters in any other way that should do just fine.
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Hey,

I think personally I would use a standard filter to do this as it will have to be set for each request. That way you get the request passed in anyway to do your logic.

Sean


I love this place!
MarK sujoKi
Greenhorn

Joined: Sep 11, 2012
Posts: 2
@Jay Abrahm

Were you able to get the request object outside of DispatchServlet? If yes, could you please share how?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

Mark. I think it would be best to create a new thread with any question that you might have. Basically, putting your question into better context.

Thanks

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting request object outside of DispatchServlet.