Tomcat 5 and JSP 2.0

I'm not Tomcat's biggest fan - and I sort of loathe the idea of having to actually rely on it. But since the price is right and it *is* the reference implementation of a Java Server, I'm moving to it on the stuff I'm developing at work and probably on my server as well (I like conformity). Though the stability and robustness may be questionable when compared to something like OrionServer, the benefits of moving to Tomcat 5 specifically are pretty great since it *is* free, and I can start using the Expression Language natively (not just inside the JSTL) and start development using the Tag pages which should speed up development on the stuff I'm working on considerably.

The Tag extensions are really what I've been waiting for since I first started using JSP (pretty much since the beginning). As a quick and dirty solution to the problem .tag files solve now, I used to create a variety of methods and just put them into a massive "code.jspf" page that I would include at the top of the jsp pages. Anyone who saw the Miniblog code saw that in action. It's fugly as hell since behind the scenes the server was simply copying all that code into all the JSP servlets that were being created during the auto-compile process. But the idea was that I wanted to stay away from .java classes as much as possible while doing JSP development. It's just faster way to develop web apps with less headaches and it's generally more portable (Miniblog ran *everywhere* for example and took all of 2 minutes to set up).

I still prefer that method of web development which is why I've become such a fan of the JSTL. MVC architectures like Struts, Spring, etc. all rely on varying degrees of abstraction in order to separate the code from the presentation in the hopes of making things more maintainable, usually at the price of 200 line long XML config files and lots of waiting around for Ant to compile .java based Actions (and many times rebooting the server) before testing your changes. I question the benefits of MVC on every level when it comes to web development. I question whether all that extra forwarding around on the back end is really worth it. A struts app will undoubtedly need more memory, more processing power, more time to develop, more resources to maintain, more structure to understand and generally more of everything involved simply because it tries to artificially separate many layers which don't need much separation. Look at the success of PHP to see what I mean - it's not MVC at all, but is quite capable of producing great, robust sites and I think the number of open source PHP apps out there speak to its readability.

Despite this, I'll probably still use Struts for some things because it's a standard way of implementing Actions on the server, which I think is needed for posts from forms. But I don't like Actions in front of *every* single page request just to do basic logic. It just bugs me. Come on! Basic servlets are simple things with quick return and low overhead - you get an http request, you process it, you return some text, you're done. JSPs are just a quick way produce servlets, so they're fine too. But with Struts now suddenly, instead of relying on the Java Server companies and groups who have spent a great deal of time and effort making servlets work right, I'm going to instead throw Struts in the middle of all that, so that each request actually goes through a Request Processor which analyzes an XML file before forwarding the request to an Action, which may return something or forward it to another class which figures out which JSP page is finally called to display. It works I know, but it just goes against my general feelings of simplicity and is, in my opinion, a lot of unnecessary overhead. And those wackos with the frameworks who want to put "cross cutting" classes in there around each request as well, are just, well, wacko as well. Keeping themselves busy I think. Programmatic masturbation.

So I'll keep using some sort of MVC for those times when I'm doing something that needs some serious back end logic, but for the times that I'm doing just some page requests with a parameter? Well, that's why I'm so excited about JSP 2.0. Now I can quickly and easily implement some basic logic and sanity checking in custom tags which are super-easy to develop. I could have done this before (and actually have), but it takes either tons of JSTL c:if tags, or a custom Tag written in Java, which goes back to the slow development process and general complexity I talked about before. But that's changed with the .tag files. I can now whip up the confirmation code and validation, and just basic logic which is too light for Actions, but is too heavy for JSTL.

Let's think about the types of requests you need fill from a web browser:

The first type is the most simple: The non-parameter request. That's the type of request for a page which doesn't take parameters of any sort. Think of the index page or maybe the TOC page or the about page.

The second type is the basic parameter request: This is the type of page where you pass in a page number, for example, or a search query. Just a few parameters which usually are then passed on to the database so you can get some specific data, which you then format and give back. This type of page also may include session data, such as after you sign in, you need to check who the user is.

The third type is the form post: This is where you need to do some logic that's involved. You need to validate parameters, query or write to a db, maybe do start some out-of-process events like emailing or IMing, etc.

That's about it. Did I miss something? Well, the new .tag libraries, in my mind, will do wonders for that second type of request. I can put the logic to check parameters and session validity and maybe do customization requests or something like that, all from a centralized place, but all in a quick and easy to maintain fashion. This is a very cool thing! I need to play with the tags a bit more, but these might even be the perfect spot to put SQL queries or XML imports that can be reused on various pages.

I haven't forgotten about the rest of Servlet framework, believe me. I still like to hide the URLs from the client, so I redirect at least once through a controller servlet which uses RegEx to analyze the request URL and create automatic parameters (you can see it working right now on this site - it's all jsp. There's no .html pages to be found). I also have warmed up to using Filters to check for security, for specific pages and admin sections.

The question I have, however, is that all these fun fancy new additions to JSP are still just abstractions in their own right. Is the Expression Language performant? I've seen things online where a page with lots of JSTL c:out and c:if logic really started to bog down. Are .tag files being called as a method or through some horrible reflection magic that is slow as hell and evil? And is checking *every* request with a Filter and a RegEx process (even if it's cached) just slowing things down even more?

To me the whole name of the game is peformance by simplicity. If you can support 100,000 users a day on one crappy little Linux box on a big pipe, then you can support millions of users later on if you move up the scale to bigger, better servers later on. In order to do that, you need to keep the back end as simple as possible. A little logic and some formatting should be the only thing between your users and your data (or maybe their data as the case may be). All the rest is just overhead.

Okay, enough ranting. Back to kicking Tomcat in the behind and getting it to work. Virtual domains anyone? WTF is this so difficult?


< Previous         Next >