On Thu, 9 May 2002, Bill Boland wrote:
> Date: Thu, 9 May 2002 23:23:26 -0700
> From: Bill Boland <[EMAIL PROTECTED]>
> Reply-To: Struts Users Mailing List <[EMAIL PROTECTED]>
> To: 'Struts Users Mailing List' <[EMAIL PROTECTED]>
> Subject: RE: Q: forwarding to a servlet
>
> I agree. It is as simple as setting the path of the forward to a path
> that will invoke the servlet...but servlets may have names or mappings
> that may also be used in the path.
>
> For example, I'm using Velocity (instead of JSPs) to view the result of
> the action. Here's a snippet of the web.xml that defines the servlet:
>
> <servlet>
> <servlet-name>velocity</servlet-name>
> <servlet-class>com.acme.MyVelocityServlet</servlet-class>
>
> <!-- more stuff here -->
>
> </servlet>
>
> <servlet-mapping>
> <servlet-name>velocity</servlet-name>
> <url-pattern>*.vm</url-pattern>
> </servlet-mapping>
>
>
> Because I have a servlet mapping, all requests with paths ending in .vm
> issued on this web application invoke the velocity servlet (just like
> all the ones ending in .do are mapped to the Struts ActionServlet in my
> application.
>
> This allows a forward such as:
>
> <forward name="menu" path="/mainMenu.vm" />
>
> to invoke another servlet using mapping.
>
> If a servlet is given a name in the web.xml, it can also be invoked via:
>
> <forward name="menu" path="/servlet/velocity" />
>
> or the full class name can be used:
>
> <forward name="menu" path="/servlet/com.acme.MyVelocityServlet" />
>
Underneath the covers, Struts is just doing a RequestDispatcher.forward()
for you. Therefore, *any* servlet mapping may be used. (In fact, the
only reason you can forward to JSP pages is that the container provides a
default servlet mapping for the "*.jsp" pattern).
Note that your last example ("/servlet/com.acme.MyVelocityServlet")
depends on a *non-portable* feature called the servlet invoker, which is
mapped to "/servlet/*". While this is provided by many containers, it is
not part of the servlet spec -- portable applications should always
provide their own explicit mappings.
Craig
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>