RequestDispatcher dispatcher =
request.getRequestDispatcher("myView.jsp");
if (dispatcher == null)
{
response.sendError(500,"Could not get view ");
return;
}
dispatcher.forward(request, response);
If request is a MultiPartServletRequest then Tomcat barfs with a class cast exception in the forward method somewhere. I'm not sure that it should do that, but a workaround is to get the enclosed HttpServletRequest and use that as follows:
It might be a good idea to have such a method where you are wrapping another instance anyway.
Another solution, which might be neater, would be to return our own instance from getRequestDispatcher that wraps the real dispatcher and uses the real request in forward method call. I don't have time to look at the full ramifications of that as my workaround suffices at present.
btw, does anyone think it is legal to pass the wrapped request to the forward method (i.e. is Tomcat in the right or the wrong?)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2001-05-25
I've applied the patch.
I have not looked at the TomCat code, but I wouldn't be surprised if they made the mistake of casting to their internal object that implements HttpServletRequest instead of to the HttpServletRequest interface. Of course, this may be justified if they need to use some TomCat-specific functions in their request object.
But my money is on this issue being an unintentional oversight in the TomCat code.
- David
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
FIXED! Thanks for the code snippet. This same problem arises in BEA WebLogic 5.1 SP10. Makes you wonder who's using who's code... and I feel that this class cast exception is utter BS. Talk about Java enforcing better OO practices than CPP. Looks like a serious programmer/lack of code review error to me.
Thanks for the fix and the open source code in general. Easy to use and works out of the box. Great job.
TimJowers
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
A typical pattern might be...
RequestDispatcher dispatcher =
request.getRequestDispatcher("myView.jsp");
if (dispatcher == null)
{
response.sendError(500,"Could not get view ");
return;
}
dispatcher.forward(request, response);
If request is a MultiPartServletRequest then Tomcat barfs with a class cast exception in the forward method somewhere. I'm not sure that it should do that, but a workaround is to get the enclosed HttpServletRequest and use that as follows:
dispatcher.forward(((MultipartServletRequest)request).
getWrappedRequest(), response);
I have posted a patch for getWrappedRequest().
It might be a good idea to have such a method where you are wrapping another instance anyway.
Another solution, which might be neater, would be to return our own instance from getRequestDispatcher that wraps the real dispatcher and uses the real request in forward method call. I don't have time to look at the full ramifications of that as my workaround suffices at present.
btw, does anyone think it is legal to pass the wrapped request to the forward method (i.e. is Tomcat in the right or the wrong?)
I've applied the patch.
I have not looked at the TomCat code, but I wouldn't be surprised if they made the mistake of casting to their internal object that implements HttpServletRequest instead of to the HttpServletRequest interface. Of course, this may be justified if they need to use some TomCat-specific functions in their request object.
But my money is on this issue being an unintentional oversight in the TomCat code.
- David
FIXED! Thanks for the code snippet. This same problem arises in BEA WebLogic 5.1 SP10. Makes you wonder who's using who's code... and I feel that this class cast exception is utter BS. Talk about Java enforcing better OO practices than CPP. Looks like a serious programmer/lack of code review error to me.
Thanks for the fix and the open source code in general. Easy to use and works out of the box. Great job.
TimJowers