Struts RequestProcessor

Neat! I just implemented my own Struts RequestProcessor!

But wait, let me back up. I decided to *not* go with Tiles because after looking at what the code was like when everything was compiled, I realized that it worked just like a bunch of jsp:includes on a page. In other words, everything was a static call back to the server. So if you had a template page which had five "tiles" in it, each call to this page would actually generate 6 different server calls. Bleh! That's a *great* way to keep your server busy, but I'd rather think about scaling, thanks.

I'm doing things "the old fashioned way" in .JSP which means I'm just doing a page-directive include for my header and footer on a page, which all gets compiled down to one nice JSP Servlet class. 1 Page == 1 Call. Maybe some day I'll need the flexibility that Tiles gives me, but not until I'm running my server on some box with Gigs of memory and lots of debugging time to spare.

This is the same as a Hibernate solution. It sounds all great and hunky-dory easy to use, but all that abstraction just puts more pressure on your middleware (app server). Unless you've got Gigs of RAM and lots of CPU cycles to spare, I'd rather throw the pressure out to the DB layer where it belongs. MySQL is blazing fast, don't get in its way an don't give your app server more work for no reason.

Anyways, while messing with Tiles to figure out how it works, I learned about subclassing the RequestProcessor. Neato! Now instead of having a URLProcessor servlet which basically fowards anything that ends with .html and .xml to an Struts style action URL ("/do/URLProcessor"), I just do it within Struts. Hooray!

I got it working, but I'm still trying to figure out the way to implement it correctly from a Struts point of view. I'm just doing a "requestDispatcher.forward(request, response);" in the method now for anything that's not a "/do/" command, but I know there should be a function I can call to just forwad the processing to the URLProcessor Action right away. Still messing with it.

Struts 1.1 definitely is not bad.


Later... here's what the code looks like at the end. Works perfectly:

package com.manywhere.action;

import javax.servlet.http.*;
import org.apache.struts.action.*;

public class MWebRequestProcessor extends RequestProcessor{

        protected String processPath(HttpServletRequest request,
                                                                 HttpServletResponse response)
                throws IOException {

                String origPath = request.getServletPath();


                        request.setAttribute("originalPath", origPath);
                        return "/URLProcessor"; 

                } else {

                        return super.processPath(request, response);




< Previous         Next >