"Bailey, Jeff A" wrote:

> Well, I actually got the controller -> Action class model working
> appropriately (Thanks to all those who answered all these trivial questions
> of mine). . . .but I have another question.
>
> What sort of methods are others out there using to obtain a "match part"
> from the requestURI?  I am ripping the string apart (in a very very poor
> way) and reconstructing a "match part" by eliminating the server information
> and virtual directory information used in the application deployment.  I was
> just wondering what some others have come up with because I am fairly
> positive that mine sucks parts of the body that one should not mention on a
> list such as this :).
>

The approach I use is to map my controller servlet to a filename extension with an
entry like this in the web.xml file:

    <servlet-mapping>
        <servlet-name>MyControllerServlet</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>

which associates the ".do" suffix (implying "go do something") with the controller
servlet.  Now, my JSP pages can submit to a URL like "listCustomers.do" or
"addOrder.do" and my controller servlet can do this:

    String matchPart = request.getServletPath();
    int extension = matchPart.indexOf(".");
    if (extension >= 0)    // Strip off the extension so I can change it at will
        matchPart = matchPart.substring(0, extension);

Given the two above examples, I would get a string of "/listCustomers" or
"/addOrder" from this code, and I can use the matchPart value to look up the
appropriate action class.

>
> This isn't anything urgent as I have everything working, I was just hoping
> to see some alternative examples so I can see how mine stacks up (or
> doesn't).
>
> Thanks again for all the help to all who have contributed to the Model 2
> discussion :)
>
> -j
>

Craig McClanahan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to