Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

FrontController  RSS feed

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys I have 2 questions.

1) How can I make sure every request goes through a front controller servlet?
So I have FrontController.java, ControllerA.java, ControllerB.java.
Process is as follows:
A) Front controller receives json string
B) Parses the json string to a java object using jackson.
C) Puts the parsed object in request scope and forwards it to one of the other controllers(ControllerA or ControllerB)

My question is? How can I make sure every single request that comes in goes through the FrontController.java? Can you please provide some code. Thank you.
So if they call ControllerA.java first, it should keep the header information and forward it to the FrontController.java

2) Is having a static method call in the doGet() of a servlet thread-safe? So, StringUtilities.isNullOrEmpty(...), is that thread-safe? What if you call that same method by multiple doGet requests simultaneously, since it's static.









 
Rancher
Posts: 989
9
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Greg Bag wrote:Guys I have 2 questions.

1) How can I make sure every request goes through a front controller servlet?


You just make all your pages submit to the same url (that of the controller servlet). You would then need to pass an extra parameter to tell the controller where to forward the requests afterwards. Alternatively you could use a filter.

Greg Bag wrote:
2) Is having a static method call in the doGet() of a servlet thread-safe? So, StringUtilities.isNullOrEmpty(...), is that thread-safe? What if you call that same method by multiple doGet requests simultaneously, since it's static.


Yes it's safe. Whether the method is static or not does not make it thread safe or not thread safe. What is important is whether you are changing variables that are being accessed by other threads e.g if you declared instance variables in the servlet then methods that access those variables are not thread safe (whether they be static or non-static).
 
Greg Bag
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Armitage you're always helping me! Thank you man.
 
Author and ninkuma
Marshal
Posts: 66797
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See FrontMan in my signature below for an example of a front controller implementation.

You can also use a prefix mapping, such as as /whatever/* to map requests to the front controller, where * denotes the command to execute. This is a more modern design than using params.

Be careful about what you catch. You don't want to fields requests for images, scripts and the like.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!