CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Servlet Syntax

  1. #1
    Join Date
    Sep 1999
    Posts
    10

    Servlet Syntax

    Greetings Gurus! I need help understanding this syntax:

    ServletInputStream sis = req.getInputStream();
    byte[]buf = new byte[4096];
    sis.read(buf);
    String name = new String(buf).trim().toUpperCase();
    PrintWriter pw = res.getWriter();

    It's really the 4th line that confuses me. I didnt know that syntax is legal. Could someone explain to me in detail 'String(buf).trim().toUpperCase()? In fact explaining the whole thing wouldnt hurt . NOTE: I do know that the PrinterWriter object can be replaced by the ServletOutputStream object. I didnt know u can have a type byte[] variable. I need a clearer understanding of what this does.

    Thanks!
    Dino







  2. #2
    Join Date
    Jun 1999
    Location
    Atlanta, GA
    Posts
    57

    Re: Servlet Syntax


    String name = new String(buf).trim().toUpperCase();
    // is equal to
    Sting name = new String(buf); // Creates a String oject of buf.
    name = name.trim(); // removes the white spaces.
    name = name.toUpperCase(); // converts the value to upper case...






    Meher

  3. #3
    Join Date
    Sep 1999
    Posts
    10

    Re: Servlet Syntax

    Thanks Meher.

    I just found the interpretation of that line while reading your response. Yes it just calls the constructor with a 'buf' parameter then it removes white spaces by .trim() then converts the value to Uppercase using .toUpperCase().
    from a left to right order. I just didnt know that syntax was legal. Perhaps the authors of my book were simply too lazy to write the methods individually but thanks for the reply anyway.

    Dino


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured