oups yes, this is what I meant ... :)

I don't understand why you would get an error. Please have a look at
SampleServlet.java ans TestSampleServlet.java which use this technique with
no problem. You can try the sample app. to see if it works on your
environment. There is no need to wait for a fix, it should work ... ! :)

Hum .... an idea ...
If you use getServletContext().getRequestDispatcher("/WibbleWobble.jsp"), it
will look for that JSP in the web server root directory, not in your context
directory ! Check the second mail I sent you.
So you probably have to do something like
getServletContext().getRequestDispatcher("/<yourcontext>/WibbleWobble.jsp")
instead.

Thanks
-Vincent

----- Original Message -----
From: "Jon Belinfante" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, July 03, 2001 12:31 PM
Subject: Re: Help :: Problem testing Servlet methods that forward to JSPs


> Vincent
> I assume you mean getServletConfig() and not getConfig().
>
> When I run the test with
>
> String forwardURL = ("/WibbleWobble.jsp");
> RequestDispatcher dispatcher =
> getServletConfig().getServletContext().getRequestDispatcher( forwardURL );
> dispatcher.forward(request, response );
>
>
> I get the same error.
> Is there no way around this using Tomcat 3.2 and I thus need to wait until
a
> patch fix
>
> Jon
>
>
>
> |--------+----------------------->
> |        |          "Vincent     |
> |        |          Massol"      |
> |        |          <vmassol@octo|
> |        |          .com>        |
> |        |                       |
> |        |          03/07/01     |
> |        |          12:21        |
> |        |          Please       |
> |        |          respond to   |
> |        |          "Vincent     |
> |        |          Massol"      |
> |        |                       |
> |--------+----------------------->
>
>---------------------------------------------------------------------------
-|
>   |
|
>   |       To:     Jon Belinfante/London/CWB@CWB,
|
>   |       [EMAIL PROTECTED]
|
>   |       cc:
|
>   |       Subject:     Re: Help  :: Problem testing Servlet methods that
|
>   |       forward to JSPs
|
>
>---------------------------------------------------------------------------
-|
>
>
>
>
> getConfig() is inherited from GenericServlet. If your class extends
> HttpServlet, then it extends GenericServlet ...
> -Vincent
>
> ----- Original Message -----
> From: "Jon Belinfante" <[EMAIL PROTECTED]>
> To: "Vincent Massol" <[EMAIL PROTECTED]>;
> <[EMAIL PROTECTED]>
> Sent: Tuesday, July 03, 2001 12:10 PM
> Subject: Re: Help :: Problem testing Servlet methods that forward to JSPs
>
>
> > Vincent
> >
> > You state use of line
> >
> > RequestDispatcher dispatcher =
> > getConfig().getServletContext().getRequestDispatcher(forwardURL);
> >
> > From where do I get getConfig and getServletContext from with in the
> Servlet
> > code ?
> >
> > Cheers and thanks for the help.
> > Jon
> >
> >
> >
> >
> >
> > |--------+----------------------->
> > |        |          "Vincent     |
> > |        |          Massol"      |
> > |        |          <vmassol@octo|
> > |        |          .com>        |
> > |        |                       |
> > |        |          03/07/01     |
> > |        |          11:53        |
> > |        |          Please       |
> > |        |          respond to   |
> > |        |          "Vincent     |
> > |        |          Massol"      |
> > |        |                       |
> > |--------+----------------------->
> >
>
>---------------------------------------------------------------------------
> -|
> >   |
> |
> >   |       To:     Jon Belinfante/London/CWB@CWB,
> |
> >   |       [EMAIL PROTECTED]
> |
> >   |       cc:
> |
> >   |       Subject:     Re: Help  :: Problem testing Servlet methods that
> |
> >   |       forward to JSPs
> |
> >
>
>---------------------------------------------------------------------------
> -|
> >
> >
> >
> >
> >
> > ----- Original Message -----
> > From: "Jon Belinfante" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>; "Vincent Massol"
> > <[EMAIL PROTECTED]>
> > Sent: Tuesday, July 03, 2001 11:12 AM
> > Subject: Help :: Problem testing Servlet methods that forward to JSPs
> >
> >
> > > I have a Servlet method that as follows that is meant to do no more
then
> > forward
> > > to a test JSP page called WibbleWobble
> > >
> >
>
> --------------------------------------------------------------------------
> > ---------------------------------------
> > >
> > >      protected void doPost(
> > >           HttpServletRequest request,
> > >           HttpServletResponse response)
> > >                throws ServletException, java.io.IOException
> > >      {
> > >           System.out.println ("Starting : " +new Date());
> > >           try
> > >           {
> > >
> > >                String forwardURL = ("/WibbleWobble.jsp");
> > >                RequestDispatcher dispatcher =
> > request.getRequestDispatcher(
> > > forwardURL );
> > >           dispatcher.forward(request, response );
> > >
> >
> >
> > Ok, here is the story ... :)
> >
> > 1/ If you look at the Tomcat implementation (for Tomcat 3.x and before
> > only - It is fixed for later version as they had to fix this to support
> > Servlet 2.3 Filters), you'll see that the forward() and include()
methods
> do
> > a cast of the request object to their own internal object. As the
Request
> > wrapper does not implement this internal object, it fails.
> >
> > 2/ The solution I have found for this was to wrap the Servlet Context.
But
> > in order to wrap the servlet context I also had to wrap the Config
object.
> > So that config.getServletContext() would return the wrapped context and
> then
> > config.getServletContext().getRequestDispatcher() would return the
wrapped
> > dispatcher. Thus when you would call forward() or include() on that
> wrapped
> > dispatcher it would actually pass the *original* request to the real
> > dispatcher foward() or include() method !
> >
> > 3/ Apparently I have forgotten that there is another way to get a
request
> > dispatcher ! Through the request, like request.getDispatcher() ! This is
a
> > bug which has *not* been corrected. I'll correct it asap. In the
meantime,
> > you can use the following, which will work (as evidenced in the Cactus
> suite
> > of tests) :
> >
> > String forwardURL = ("/WibbleWobble.jsp");
> > RequestDispatcher dispatcher =
> > getConfig().getServletContext().getRequestDispatcher(forwardURL);
> > dispatcher.forward(request, response );
> >
> > Note that you will need to have an init in your test method so that
> > getConfig() returns the wrapped config object (as you were already
doing)
> :
> >
> > SecurityServlet servlet = new SecurityServlet();
> > servlet.init(config); <-- needed
> > servlet.doPost( request, response );
> >
> > Thanks to both of you for this bug discovery and sorry Jari, I have
> probably
> > skipped your mail that already mentionned that problem (or maybe I
simply
> > did not understand the issue at that time) ... I'll correct it quickly
...
> >
> > -Vincent
> >
> >
> >
> >
> >
> >
>
>
>
>
>
>

Reply via email to