File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes HttpServletRequest, getServletPath as controller Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpServletRequest, getServletPath as controller" Watch "HttpServletRequest, getServletPath as controller" New topic
Author

HttpServletRequest, getServletPath as controller

Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2061
Any one has experience where getServletPath is not useful (not reliable) in determining which path was used to connect to the servlet?

Servlet 2.4 specs


My code


My descriptor


(As you can see, I did not use /*)

[ December 15, 2006: Message edited by: Jesus Angeles ]
[ December 15, 2006: Message edited by: Jesus Angeles ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

First and foremost, why on earth use if-then-else rather than separate servlets? What a mess!

If you are trying to create a unified Front Controller, if-then-else is still not the way to go. Look into the Command pattern.

Secondly, things can get complicated when dealing with includes and forwards. Is this the case?
[ December 15, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

By the way, I have no idea what the "req" in your subject is supposed to mean. Please use real words when posting.
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2061
My design (although working) may need improvement. (I have an excuse, its my first, and only 6 months into j2ee design/implement. But yes, there is no excuse for stuff blowing up in production.)

But the application was installed already last week, and I am researching if that sole logic on 'control' is bullet-proof.

That is:
1. The (j2ee) system will allow entry, only on those 3 servlet mapping (The class are inside web-inf, therefore are not accessible directly? ; whether server was set to allow direct or indirect component access).

2. That that method getServletPath will return those 3 exact String.

(The system is on https and has authentication.)
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2061
I might have used some sort of pattern, but I did not intend to do so. My design was simply brought by a huge logic that I could have broken down to methods or classes.

(I edited the title, for the 'req')
[ December 15, 2006: Message edited by: Jesus Angeles ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpServletRequest, getServletPath as controller