Sanjay Sharma wrote:

> Hi all,
> I'm trying to make the controller servlet mapping work in Model 2
> architecture,to get the Action class from a hashtable.
>
> Here is what I have done.
>
> In a JSP file:
> <form name="shoppingForm"
>    action="/musicshop/servlet/ShoppingServlet/MainJSP.do"
>    method="POST">
>
> In web.xml of the application (using Tomcat):
>
>    <servlet-mapping>
>         <servlet-name>ShoppingServlet</servlet-name>
>         <url-pattern>*.do</url-pattern>
>     </servlet-mapping>
>
> In the controller servlet:
>
>         String matchPart = req.getServletPath();
>         System.out.print("Value before truncating: ");
>         System.out.println(matchPart);
>         int extension = matchPart.indexOf(".");
>         if (extension >= 0)
>            matchPart=matchPart.substring(0, extension);
>
> What I get in getServletPath() is /servlet/ShoppingServlet.
> What am I doing wrong here?
> Thanks,
> Sanjay
>

If "/musicshop" is your context path, that is exactly what you are supposed to
get.  The getServletPath() method returns the part of the request URI, after the
context path, that was used to select which servlet should be executed.  When using
extension matching, that means *everything* after the context path, because
extension matching only happens after the last slash character.

What did you expect to get?

Craig McClanahan

====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat

===========================================================================
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