You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Azariah Jeyakumar <az...@tumbleweed.com> on 2001/05/18 02:10:32 UTC

Re: How does one forward a POST request when the POST data has al ready been processed?

Hi,
I am facing the exact same problem that has been described below.
Once the first servlet has read and used up the data in the request's
ServletInputStream, any other JSP or servlet to which the request is
forwarded to will face an inconsistent situtaion: The contentType, method,
etc say that some POST data should be expected, but there is no real POST
data because the upstream servlet has already read the data.
May be the first servlet can communicate to the second servlet via a special
request attribute that the inputStream has been read?
In a framework environment such as struts, this is a bigger problem because
the second servlet (which is comprised of ActionServlet, RequestUtils,
DiskMultipartRequestHandler, MultipartIterator classes) has no generalized
way of knowing that the request's input stream has been read already and
Struts tries to process direct requests from the browser in the same way as
forwarded requests.
Thanks
Azariah

Re: How does one forward a POST request when the POST data has al read y
been processed?

*	From: Duane Morse 
*	Subject: Re: How does one forward a POST request when the POST data
has al read y been processed? 
*	Date: Thu, 30 Nov 2000 09:20:33 -0800 

That's exactly what's happening, which is the reason for my question.  If
one
wants to separate business processing from presentation, using servlets and
EJBs
for the former and JSPs for the latter, then how does one dispatch to the
JSP
when the data the JSP needs is in special request attributes?  My JSP is
making
no calls to retrieve form variables, but apparently Tomcat 3.2b8 is trying
to set
things up so it could -- since the servlet has already processed the input,
that's
an error.  So is there NO way to divide the labor in this fashion?  How do
you
EVER have servlets (and JSPs) pass work among themselves if the framework is
going
to do this sort of thing?  The first time a servlet opens the input stream
and
reads the POST data, all subsequent servlets and JSPs are screwed.

-----Original Message-----
From: Albert Wong [<ma...@ECHARGE.COM>]
Sent: Wednesday, November 29, 2000 5:06 PM
To: SERVLET-INTEREST@JAVA.SUN.COM
Subject: Re: How does one forward a POST request when the POST data has
al read y been processed?


Typically information to be displayed by the JSP is communicated via the
ServletRequest.setAttribute and the RequestDispatcher.  For example,
ServletA performs the business logic and stores the results using
setAttribute(java.lang.String name, java.lang.Object o), and the servlet or
jsp retreives the information using getAttribute(java.lang.String name).

If your servlet performing the business logic already called
ServletResponse.getOutputStream() or ServletResponse.getWriter() before
calling RequestDispatcher.forward then that might explain the behavior your
experiencing with Tomcat (it's not allowed by the Servlet Spec).


-----Original Message-----
From: Duane Morse [<ma...@ELDOCOMP.COM>]
Sent: Wednesday, November 29, 2000 3:27 PM
To: SERVLET-INTEREST@JAVA.SUN.COM
Subject: How does one forward a POST request when the POST data has
alread y been processed?


I ran into a problem with the Tomcat 3.2-b8 release, and it has implications
beyond the Tomcat
implementation; hence my posting here.

I have a servlet which processes a form which uses the POST method, and it
forwards the request
to another servlet (in this case,  a JSP) after adding a data structure to
the request object which
the target servlet should use to format the response page.  This is your
classic "let JSP handle
the presentation" mode of operations.  Since the real response data is in my
own data object,
the target servlet ignores the original input.  Tomcat's problem with this
is that it apparently tries to
prepare the target for processing POST data, but the data has already been
read, so it gets a
"short data" error (i.e., CONTENT_LENGTH is n, but the number of data bytes
in the stream is 0).

I can't see any way of changing the method type or the content length in the
request object before
forwarding it.  How should I invoke a servlet in a manner that doesn't
potentially confuse the servlet container?

Duane Morse, Eldorado Computing Inc., Phoenix AZ