You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by "Mark T. Miller" <mm...@gadgetspace.com> on 2001/06/06 18:27:35 UTC
Re: [Beta5]HttpRequestBase POST buglet
I have attached a simple servlet, and form. This servlet works
correctly with Tomcat 3.2.1. With Tomcat 4 Beta5, the getParameter
calls return null. Note that this problem is when using the "builtin"
HTTP connector. This must be a bug!
---- simple servlet -----
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** Simple servlet that reads three parameters from the
* form data.
* <P>
* Taken from Core Servlets and JavaServer Pages
* from Prentice Hall and Sun Microsystems Press,
* http://www.coreservlets.com/.
* © 2000 Marty Hall; may be freely used or adapted.
*/
public class ThreeParams extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "Reading Three Request Parameters";
out.println("<HTML><HEAD><TITLE>" + title + "</TITLE></HEAD>\n" +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1 ALIGN=CENTER>" + title + "</H1>\n" +
"<UL>\n" +
" <LI><B>param1</B>: "
+ request.getParameter("param1") + "\n" +
" <LI><B>param2</B>: "
+ request.getParameter("param2") + "\n" +
" <LI><B>param3</B>: "
+ request.getParameter("param3") + "\n" +
"</UL>\n" +
"</BODY></HTML>");
}
}
------ The form to drive it ------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Collecting Three Parameters</TITLE>
</HEAD>
<BODY BGCOLOR="#FDF5E6">
<H1 ALIGN="CENTER">Collecting Three Parameters</H1>
<FORM method="POST" ACTION="http://localhost:8080/servlet/ThreeParams">
First Parameter: <INPUT TYPE="TEXT" NAME="param1"><BR>
Second Parameter: <INPUT TYPE="TEXT" NAME="param2"><BR>
Third Parameter: <INPUT TYPE="TEXT" NAME="param3"><BR>
<CENTER>
<INPUT TYPE="SUBMIT">
</CENTER>
</FORM>
</BODY>
</HTML>
"Craig R. McClanahan" wrote:
> I don't think this patch is what we really want to do.
>
> Currently, the code is testing for all of the following conditions before
> trying to parse request parameters from the input stream:
> 1) The HTTP method is "POST"
> 2) The content length is greater than zero
> 3) The servlet has never called getInputStream() or getReader()
> 4) The content type is the required value
>
> Your patch would change test (3) to require that the servlet *must* have
> called getInputStream() or getReader() first, which would break a large
> number of existing servlets.
>
> Do you have a test case that demonstrates a problem? I've got lots of
> different web apps that seem to have no problems reading POST-ed request
> parameters.
>
> On Mon, 21 May 2001, Mark T. Miller wrote:
>
> >
> > [I sent this to the users list on Friday - someone sent me email
> > telling me I should send it to this group - sorry for the double
> > post]
> >
> > I just started using TomCat B5 using the builtin HTTPConnector.
> > When POST-ing a form, none of the name-value pairs of the
> > "Query string" make it through.
> >
> > I found the below minor logic bug, and it now is working for me.
> >
> > --- HttpRequestBase.java.orig Fri May 18 16:36:30 2001
> > +++ HttpRequestBase.java Fri May 18 16:39:40 2001
> > @@ -616,7 +616,7 @@
> > if (semicolon >= 0)
> > contentType = contentType.substring(0, semicolon).trim();
> > if ("POST".equals(getMethod()) && (getContentLength() > 0)
> > - && (this.stream == null)
> > + && (this.stream != null)
> > && "application/x-www-form-urlencoded".equals(contentType)) {
> > try {
> > int max = getContentLength();
> >
> >