----------------------------------------------------------------
BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
WHEN YOU POST, include all relevant version numbers, log files,
and configuration files.  Don't make us guess your problem!!!
----------------------------------------------------------------

jon * wrote:
 
> Your code that deals with POST.

I seem to be having a similar problem.  This code works fine with the
count set to something less than 100.  At about 100 (with a content
length of around 1200) the HttpServletRequest doesn't have any of the
parameters.

Invoke with /servlet/xxx?count=nnn, play with the nnn and at some point
you'll see the "it's whacked" message.


(Sorry 'bout the formatting.)



import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Enumeration;


public class JServLostParameterBugServlet extends HttpServlet
{

  protected void doGet( HttpServletRequest request,
                        HttpServletResponse response )
    throws ServletException, IOException
    {
    response.setContentType( "text/html" );
    sendResponse( request, response, response.getOutputStream() );
    }


  protected void doPost( HttpServletRequest request,
                         HttpServletResponse response )
    throws ServletException, IOException
    {
    log( "doPost" );
    response.setContentType( "text/html" );
    sendResponse( request, response, response.getOutputStream() );
    }


  private void sendResponse( HttpServletRequest request,
                             HttpServletResponse response,
                             ServletOutputStream out )
    {
    try
      {
      out.println( "<HTML><HEAD><TITLE>Lose My
Parameters!</TITLE></HEAD>" );
      out.println( "<BODY>" );

      int checkboxCount = 80;
      if ( request.getParameter( "count" ) != null )
        {
        try
          {
          checkboxCount = Integer.parseInt( request.getParameter(
"count" ) );
          }
        catch ( Exception exception )
          {
          exception.printStackTrace( System.err );
          }
        }

      boolean itsOK = false;
      for ( Enumeration names = request.getParameterNames();
names.hasMoreElements(); )
        {
        String name = (String)names.nextElement();
        if ( ! name.startsWith( "count" ) ||  "get".equalsIgnoreCase(
request.getMethod() ) )
          itsOK = true;
        }
      if ( ! itsOK )
        out.println( "<B><FONT COLOR=\"red\">If you see this, it's
whacked.</font></b><P>" );

      out.println( "<HR>" );
      out.println( "The content length is " + request.getContentLength()
);
      out.println( "<hr>" );
      sendForm( request, response, out, checkboxCount );

      for ( Enumeration names = request.getParameterNames();
names.hasMoreElements(); )
        {
        String name = (String)names.nextElement();
        out.print( "<LI><B>" + name + "</B>: " );
        String values[] = request.getParameterValues( name );
        for ( int i = 0; i < values.length; i++ )
          {
          out.print( values[i] + "," );
          }
        out.println( "<br> " );
        }

      out.println( "</BODY></HTML>" );
      }
    catch ( IOException ioe ) {}
    }

  
  private void sendForm( HttpServletRequest request,
                         HttpServletResponse response,
                         ServletOutputStream out,
                         int checkboxCount)
    throws IOException
    {
    out.println( "<FORM ACTION=\"" + request.getRequestURI() + "?count="
+
                 checkboxCount +"\" METHOD=\"POST\">" );
    
    out.println( "Textfield: <INPUT NAME=textfield1 value=\"eat me\">"
);
    out.println( "<BR>" );
    out.println( "Select: <SELECT name=selection>" );
    String foo[] = {"this sucks", "this rules" };
    for ( int i = 0; i < foo.length; i++ )
      {
      out.println( "<OPTION>" + foo[i] );
      }
    out.println( "</SELECT>" );
    out.println( "<BR>" );

    out.println( "Checkbox: <INPUT type=checkbox name=checkme> ON" );
    out.println( "<BR>" );

    out.println( "Radio1: <INPUT type=radio name=radio value=1>" );
    out.println( "Radio2: <INPUT type=radio name=radio value=2>" );
    out.println( "Radio3: <INPUT type=radio name=radio value=3>" );
    out.println( "<BR>" );

    out.println( "<INPUT TYPE=submit>" );
    out.println( "<BR>" );
    for ( int i = 0; i < checkboxCount; i++ )
      {
      out.println( "<input type=hidden name=hidden" + i + " value=" + i
+ ">" );
//       out.println( "Box" + i + " <input type=checkbox
name=checkboxen" + i + " checked><br>" );
      }
    out.println( "</FORM>" );
    }

}


--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html>
Problems?:           [EMAIL PROTECTED]

Reply via email to