my dog learned polymorphism
The moose likes Servlets and the fly likes Front controller that doesn't stink Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Front controller that doesn Watch "Front controller that doesn New topic

Front controller that doesn't stink

Antoine Koskoz

Joined: Feb 28, 2010
Posts: 9
Hi guys,

I'm tryng to write a Front Controller which can process my urls like this: http://url/controller/method
The idea is ot intercept all the URLs in the web.xml and to route them to the FrontController. Then, the FrontController would call the right method in the right controller (servlet) and pass them the ServletContext and the response et request object.

I've wrote this implementation of my idea:

The issue here is, whenever I call the forward method in my Foo controller, I've got a so big stack trace that I cannot have the original exception...
It looks like this:

Any help would be nice, or if you have a better method to implement my idea I'd be glad to hear it but I don't want to use any framework, i's for purpose learning only. Of course, in a real application I'd use a framework.

Dieter Quickfend

Joined: Aug 06, 2010
Posts: 543

What is your exception exactly?

Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Antoine Koskoz

Joined: Feb 28, 2010
Posts: 9
I can't access to the beginning of the stacktrace, it floods my console :/
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

But you're running this front controller in some kind of container, right? (Tomcat, JBoss, Websphere...) So configure that to write logs to a file. In fact it may already be configured that way and you just have to find the log files.
Antoine Koskoz

Joined: Feb 28, 2010
Posts: 9
I think it has something to do with my web.xml because I solved the issue.

Here is my latest implementation, please tell me what do you think about it.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63870

Think about this:

[Asking smart questions] [About Bear] [Books by Bear]
Antoine Koskoz

Joined: Feb 28, 2010
Posts: 9
Yes, I could return a http 500.
Saulo Siqueira

Joined: Mar 27, 2012
Posts: 2
Your servlet FrontController is mapped to which urlpatterns receive?
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
Why have you made all methods in controller static? Have you considered about thread safety?
I agree. Here's the link:
subject: Front controller that doesn't stink
It's not a secret anymore!