This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Micro Frontends in Action and have Michael Geers on-line!
See this thread for details.
Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Getting request object outside of DispatchServlet.

 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.



 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you putting this code? In a Spring MVC Controller, a Servlet, a Struts Action. We need a little more context.

Mark
 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I should have attached this earlier.

 
Mark Spritzler
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 377
Android Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Jay Abrahm

Were you able to get the request object outside of DispatchServlet? If yes, could you please share how?
 
Mark Spritzler
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Grow a forest with seedballs and this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic