Sylvain Roche wrote:
>
> Hi,
>
> I have a servlet that filters the entrance to an application (login,
> password, authorized IP, different parts of the application depending on
> the login). When the request matches an user (ie there is a record in the
> database granting access the part of the application specified in the
> request), the request if forwarded to the right servlet, in charge of the
> business logic, by a RequestDispatcher.
>
> When the request is multipart, the uploaded files part are recorded in the
> checkpoint servlet, but the request dispatcher dispatches nothing but the
> headers, as long as the files have already been received (it's push), and
> the request is empty (all the parameters are received through the
> MultipartRequest and what's forwarded by the RequestDispatcher is an
> HttpServletRequest. And the second servlet gets a header saying that the
> content type of the request is multipart/form-data, and an empty simple
> http request.
>
> I've been working with multipart request for 2 years, but I don't know how
> to handle this. One simple solution would be (as I always did until now) to
> group both the identification and the business logic in a single servlet,
> but this is precisely what I want to avoid.

This is a bit tricky, and the spec doesn't really say how multipart/form-data
should be handled when you forward a request using the RequestDispatcher (RD).
I would suggest that you let your checkpoint servlet parse the request body,
using MultipartRequest or a similar class, and that you then pass the parsed
result on to the business logic servlet as a request attribute. The business
logic servlet must be aware of this, of course, so it knows how to extract
the request data. It's not what you were hoping for, I'm sure, but I believe
it's the only portable solution in a Servlet 2.2 container.

Servlet 3.3 removes the restriction that the request and response objects you
pass on through the must be the same as you receive, so here you could
create your own request wrapper that deals with this and let your business
logic servlet be less aware of the internals.

Hans
--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com
Author of JavaServer Pages (O'Reilly), http://TheJSPBook.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
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