6 Replies Latest reply: Feb 21, 2011 8:24 AM by gimbal2 RSS

    How can we detect the size for doGet(

    Prem
      Hi ,

      Who verifies the size of data to be sent to doGet() method which is by default 256 char?

      Because i just tried following example and it executed fine

      index.jsp

      <form action="MyServlet" method="get">
           <input type="text" name="id" value="aslkdfaslkdfjaslfkjasdflkjsadfjffalsdjfsadfjsadlfjsadlfkjasdflkjasdflkasdjfslakdjasdlkjasdlkjsdalkfjsalkfjsafklasjdflksajfaslkdfjsadlkfjsalkfjasflkasjflkasflksajfaslkfjaslkfjsafklsajdfklsajdfksaldjfsakdlfjsaklfsaklfsaklfsadkflsajdkljsadkljaskdljaskdlsakdl123457890123456">
           <input type="submit">
           </form>


      And MyServlet.java



      import java.io.IOException;
      import javax.servlet.ServletException;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;

      /**
      * Servlet implementation class for Servlet: MyServlet
      *
      */
      public class MyServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
      static final long serialVersionUID = 1L;

      /* (non-Java-doc)
           * @see javax.servlet.http.HttpServlet#HttpServlet()
           */
           public MyServlet() {
                super();
           }      
           
           /* (non-Java-doc)
           * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
           */
           protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                String s=request.getParameter("id");
                System.out.println(s.length());
           }      
           
           /* (non-Java-doc)
           * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
           */
           protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                // TODO Auto-generated method stub
           }           
      }

      above code is working fine...

      Edited by: Prem on Feb 20, 2011 7:24 AM
        • 1. Re: How can we detect the size for doGet(
          jtahlborn
          where did you get the idea that a get url was limited to 256 chars?
          • 2. Re: How can we detect the size for doGet(
            EJP
            Who verifies the size of data to be sent to doGet() method which is by default 256 char?
            Nobody 'verifies' it and there is no such default.
            above code is working fine...
            Why did you expect otherwise?
            • 3. Re: How can we detect the size for doGet(
              gimbal2
              jtahlborn wrote:
              where did you get the idea that a get url was limited to 256 chars?
              To defend to OP I too read that at some point in time some older browsers had a limitation on the length of an URL. Using a POST request would allow you to work around that limitation.

              I haven't read anything like that recently though; I wouldn't know if it would still be true for any browser today.
              • 4. Re: How can we detect the size for doGet(
                ramp
                gimbal2 wrote:
                jtahlborn wrote:
                where did you get the idea that a get url was limited to 256 chars?
                To defend to OP I too read that at some point in time some older browsers had a limitation on the length of an URL. Using a POST request would allow you to work around that limitation.

                I haven't read anything like that recently though; I wouldn't know if it would still be true for any browser today.
                I second that. As far as I could research there is no specific directive, but I wouldn't want to deal with such issues in production especially when it can safely be replaced by 'POST'.

                http://stackoverflow.com/questions/2659952/maximum-length-of-http-get-request
                http://www.coderanch.com/t/122699/HTML-JavaScript/request-length-limitation
                http://support.microsoft.com/default.aspx?scid=KB;en-us;q208427

                cheers,
                ram.
                • 5. Re: How can we detect the size for doGet(
                  EJP
                  So:

                  (a) there is a recommendation of <= 255 chars in HTTP 1.1

                  (b) there is no 'default' or 'verification'

                  (c) practical limits of 2k or more are enforced at some browsers

                  (d) the OP has no specific reason to expect a length just above 256 bytes to fail.
                  • 6. Re: How can we detect the size for doGet(
                    gimbal2
                    EJP wrote:
                    So:

                    (a) there is a recommendation of <= 255 chars in HTTP 1.1

                    (b) there is no 'default' or 'verification'

                    (c) practical limits of 2k or more are enforced at some browsers

                    (d) the OP has no specific reason to expect a length just above 256 bytes to fail.
                    I'd more wrap up in:

                    e) He has no reason to believe any of us or anything written on some internet page. There is only one realistic thing to do: install ever browser you want to support and test it out. If there are no issues, be blissfully ignorant. If there are: do the right thing and use POST requests to prevent 'large' url strings.